-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectTest.java
102 lines (87 loc) · 2.58 KB
/
ProjectTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* The test class ProjectTest for student test cases.
* Add all new test cases to this task.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ProjectTest
{
/**
* Default constructor for test class ProjectTest
*/
public ProjectTest()
{
}
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
@Before
public void setUp()
{
}
/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
@After
public void tearDown()
{
}
//TODO add new test cases from here include brief documentation
@Test(timeout=1000)
public void testSensibleToStringSize() {
NgramAnalyser analyser = new NgramAnalyser("aabcabfaacfaaac");
int minLines = analyser.getAlphabetSize() + 1;
//This next bit is ridiculously inefficient memory wise but I'm lazy so there.
String[] lines = analyser.toString().split("\r\n|\r|\n");
int linesLength = lines.length;
//System.out.println(linesLength);
//System.out.println(minLines);
assertTrue(linesLength >= minLines);
}
@Test(timeout=1000)
public void testGetDistinctNgrams() {
NgramAnalyser analyser = new NgramAnalyser("aaa");
NgramAnalyser analyser1 = new NgramAnalyser(3, "abc");
NgramAnalyser analyser2 = new NgramAnalyser(3, "bcbabbcbc");
NgramAnalyser analyser3 = new NgramAnalyser(2, "baba");
assertEquals(analyser.getDistinctNgrams().size(),1);
assertEquals(analyser1.getDistinctNgrams().size(),3);
assertEquals(analyser2.getDistinctNgrams().size(),6);
assertEquals(analyser3.getDistinctNgrams().size(),2);
}
@Test(timeout=1000)
public void testLaplaceExample() {
MarkovModel mkMdl = new MarkovModel(2, "aabcabaacaac");
double c = mkMdl.laplaceEstimate("aac");
double b = mkMdl.laplaceEstimate("aab");
double a = mkMdl.laplaceEstimate("aaa");
//System.out.println(c);
assertTrue(c >= 0.4999 && c <= 0.5001);
assertTrue(b >= 0.3332 && b <= 0.3334);
assertTrue(a >= 0.1666 && a <= 0.1668);
}
@Test(timeout=1000)
public void testSimpleExample() {
MarkovModel mkMdl = new MarkovModel(2, "aabcabaacaac");
double b = mkMdl.simpleEstimate("aab");
//System.out.println(b);
assertTrue(b == (1.0/3.0));
}
@Test
public void testTask3example()
{
MarkovModel model = new MarkovModel(2,"aabcabaacaac");
ModelMatcher match = new ModelMatcher(model,"aabbcaac");
//Precision issues are amazing...
assertEquals(-0.3849, match.getAverageLogLikelihood(), 0.0001);
}
}