This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix thread-safety for word counts; avoid recounts
- Loading branch information
Showing
5 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
server/zanata-model/src/test/java/org/zanata/util/OkapiUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.zanata.util; | ||
|
||
import static org.zanata.util.OkapiUtil.*; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
@Test(groups = { "unit-tests" }) | ||
public class OkapiUtilTest | ||
{ | ||
String[] strings = | ||
{ | ||
"<author><firstname>Emmanuel</firstname> <surname>Bernard</surname></author>", | ||
"Graphic Design", | ||
"the object is passed up to the UI tier", | ||
|
||
"// in the first session\n" + | ||
"Cat cat = (Cat) firstSession.load(Cat.class, catID);\n" + | ||
"\n" + | ||
"// in a higher tier of the application\n" + | ||
"Cat mate = new Cat();\n" + | ||
"cat.setMate(mate);\n" + | ||
"\n" + | ||
"// later, in a new session\n" + | ||
"secondSession.saveOrUpdate(cat); // update existing state (cat has a non-null id)\n" + | ||
"secondSession.saveOrUpdate(mate); // save the new instance (mate has a null id)" | ||
}; | ||
long[] count = | ||
{ | ||
8, | ||
2, | ||
9, | ||
// 4+8+7+4+3+5+11+12 = 54 ? | ||
49 | ||
}; | ||
@Test | ||
public void testCountWords() | ||
{ | ||
countWords(null, "en-US"); | ||
int i=0; | ||
for (String s : strings) | ||
{ | ||
long expected = count[i++]; | ||
long n = countWords(s, "en-US"); | ||
Assert.assertEquals(n, expected); | ||
// if (n == 0) | ||
// Assert.fail(s + ":" + n); | ||
// else | ||
// System.out.println(n); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters