public void testTestSerializable () throws IOException, ClassNotFoundException { WriteMe w = new WriteMe (); w.foo = "hi there"; w.bar = 1; WriteMe w2 = (WriteMe) cloneViaSerialization (w); assertTrue (w != w2); assertTrue (w.equals (w2)); }
public void testDotProductSparseASVToSV () { SparseVector v = makeSparseVectorToN (7); AugmentableFeatureVector afv = makeAfv (new int[] { 1, 3 }, false); double dp = afv.dotProduct (v); assertEquals (4.0, dp, 1e-5); afv = makeAfv (new int[] { 2, 5 }, false); dp = afv.dotProduct (v); assertEquals (7.0, dp, 1e-5); }
public static void main (String[] args) { // saveOldSv (); junit.textui.TestRunner.run (suite()); }
public void testSerializable () throws IOException, ClassNotFoundException { IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrix (); IndexedSparseVector sPrime = (IndexedSparseVector) TestSerializable.cloneViaSerialization (s); assertEquals (s.numLocations (), sPrime.numLocations ()); assertTrue (Arrays.equals (s.getIndices (), sPrime.getIndices ())); assertTrue (Arrays.equals (s.getValues (), sPrime.getValues ())); }
/** Tests how serializing labels separately can lead to big losses. * This currently fails. I'm not sure what to do about this. -cas */ public void testReadResolve () throws IOException, ClassNotFoundException { LabelAlphabet dict = new LabelAlphabet (); dict.lookupIndex ("TEST1"); dict.lookupIndex ("TEST2"); dict.lookupIndex ("TEST3"); Label t1 = dict.lookupLabel ("TEST1"); Labelee l = new Labelee (dict, t1); Labelee l2 = (Labelee) TestSerializable.cloneViaSerialization (l); assertTrue (l.dict == l2.dict); assertTrue (dict.lookupLabel("TEST1") == l.theLabel); assertTrue (dict.lookupLabel("TEST1") == l2.theLabel); assertTrue (l.theLabel == l2.theLabel); }
public void testReadResolve () throws IOException, ClassNotFoundException { Alphabet dict = new Alphabet (); dict.lookupIndex ("TEST1"); dict.lookupIndex ("TEST2"); dict.lookupIndex ("TEST3"); Alphabet dict2 = (Alphabet) TestSerializable.cloneViaSerialization (dict); assertTrue (dict == dict2); }
public void testSerializable () throws Exception { // Write out the sparse vector s1 HashedSparseVector s2 = (HashedSparseVector) TestSerializable.cloneViaSerialization (s1); assertEquals (s1.numLocations (), s2.numLocations ()); for (int loc = 0; loc < s1.numLocations (); loc++) { assertEquals (s1.valueAtLocation (loc), s2.valueAtLocation (loc), 0.001); } }
public void testSerializable2 () throws IOException, ClassNotFoundException { SparseVector[][] vecs = new SparseVector[2][]; vecs[0] = new SparseVector[] { (SparseVector) s1.cloneMatrix (), (SparseVector) s1.cloneMatrix (), }; vecs[1] = new SparseVector[] { (SparseVector) s1.cloneMatrix (), }; SparseVector[][] vecsPrime = (SparseVector[][]) TestSerializable.cloneViaSerialization (vecs); assertEquals (vecs.length, vecsPrime.length); }
private void checkAnswer (HashedSparseVector actual, double[] ans) { assertEquals ("Wrong number of locations:", ans.length, actual.numLocations()); for (int i = 0; i < actual.numLocations(); i++) { assertEquals ("Value incorrect at location "+i+": ", ans[i], actual.valueAtLocation (i) , 0.0); } }
public void testEmptyLocations () { IndexedSparseVector s = new IndexedSparseVector (new int[0], new double [0]); assertEquals (0.0, s.value (38), 1e-10); assertEquals (0.0, s.dotProduct (s1), 1e-10); }
public void testMultinomial () { double[] c = new double[] {.2, .3, .1, .4}; Multinomial m = new Multinomial (c); assertTrue (m.probability (0) == .2); }
public void testNotFound () { Alphabet dict = new Alphabet (); dict.lookupIndex ("TEST1"); dict.lookupIndex ("TEST2"); dict.lookupIndex ("TEST3"); assertEquals (-1, dict.lookupIndex ("TEST4", false)); assertEquals (3, dict.size()); assertEquals (3, dict.lookupIndex ("TEST4", true)); }
public void testSetValue () { IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrix (); s.setValue (5, 0.3); double[] ans = new double[] {1, 0.3, 3, 4, 5}; for (int i = 0; i < s.numLocations(); i++) { assertTrue (s.valueAtLocation (i) == ans[i]); } }
public void testTestSerializable () throws IOException, ClassNotFoundException { WriteMe w = new WriteMe (); w.foo = "hi there"; w.bar = 1; WriteMe w2 = (WriteMe) cloneViaSerialization (w); assertTrue (w != w2); assertTrue (w.equals (w2)); }
public void testSerializable () throws IOException, ClassNotFoundException { IndexedSparseVector s = (IndexedSparseVector) s1.cloneMatrix (); IndexedSparseVector sPrime = (IndexedSparseVector) TestSerializable.cloneViaSerialization (s); assertEquals (s.numLocations (), sPrime.numLocations ()); assertTrue (Arrays.equals (s.getIndices (), sPrime.getIndices ())); assertTrue (Arrays.equals (s.getValues (), sPrime.getValues ())); }
/** Tests how serializing labels separately can lead to big losses. * This currently fails. I'm not sure what to do about this. -cas */ public void testReadResolve () throws IOException, ClassNotFoundException { LabelAlphabet dict = new LabelAlphabet (); dict.lookupIndex ("TEST1"); dict.lookupIndex ("TEST2"); dict.lookupIndex ("TEST3"); Label t1 = dict.lookupLabel ("TEST1"); Labelee l = new Labelee (dict, t1); Labelee l2 = (Labelee) TestSerializable.cloneViaSerialization (l); assertTrue (l.dict == l2.dict); assertTrue (dict.lookupLabel("TEST1") == l.theLabel); assertTrue (dict.lookupLabel("TEST1") == l2.theLabel); assertTrue (l.theLabel == l2.theLabel); }
public void testDotProductSparseASVToSV () { SparseVector v = makeSparseVectorToN (7); AugmentableFeatureVector afv = makeAfv (new int[] { 1, 3 }, false); double dp = afv.dotProduct (v); assertEquals (4.0, dp, 1e-5); afv = makeAfv (new int[] { 2, 5 }, false); dp = afv.dotProduct (v); assertEquals (7.0, dp, 1e-5); }
public void testReadResolve () throws IOException, ClassNotFoundException { Alphabet dict = new Alphabet (); dict.lookupIndex ("TEST1"); dict.lookupIndex ("TEST2"); dict.lookupIndex ("TEST3"); Alphabet dict2 = (Alphabet) TestSerializable.cloneViaSerialization (dict); assertTrue (dict == dict2); }
public void testSerializable () throws Exception { // Write out the sparse vector s1 HashedSparseVector s2 = (HashedSparseVector) TestSerializable.cloneViaSerialization (s1); assertEquals (s1.numLocations (), s2.numLocations ()); for (int loc = 0; loc < s1.numLocations (); loc++) { assertEquals (s1.valueAtLocation (loc), s2.valueAtLocation (loc), 0.001); } }
public void testSerializable2 () throws IOException, ClassNotFoundException { SparseVector[][] vecs = new SparseVector[2][]; vecs[0] = new SparseVector[] { (SparseVector) s1.cloneMatrix (), (SparseVector) s1.cloneMatrix (), }; vecs[1] = new SparseVector[] { (SparseVector) s1.cloneMatrix (), }; SparseVector[][] vecsPrime = (SparseVector[][]) TestSerializable.cloneViaSerialization (vecs); assertEquals (vecs.length, vecsPrime.length); }