public static void main (String[] args) throws Throwable { TestSuite theSuite; if (args.length > 0) { theSuite = new TestSuite (); for (int i = 0; i < args.length; i++) { theSuite.addTest (new TestSerializable (args[i])); } } else { theSuite = (TestSuite) suite (); } junit.textui.TestRunner.run (theSuite); }
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 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); }
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); }
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 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 static void main (String[] args) throws Throwable { TestSuite theSuite; if (args.length > 0) { theSuite = new TestSuite (); for (int i = 0; i < args.length; i++) { theSuite.addTest (new TestSerializable (args[i])); } } else { theSuite = (TestSuite) suite (); } junit.textui.TestRunner.run (theSuite); }
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 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 ())); }
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 ())); }
public void testOneFromSerialized () throws IOException, ClassNotFoundException { Pipe p = createPipe (); Pipe clone = (Pipe) TestSerializable.cloneViaSerialization (p); InstanceList ilist = new InstanceList (clone); ilist.addThruPipe(new StringArrayIterator(data)); assertTrue (ilist.size() == 3); }
public void testOneFromSerialized () throws IOException, ClassNotFoundException { Pipe p = createPipe (); Pipe clone = (Pipe) TestSerializable.cloneViaSerialization (p); InstanceList ilist = new InstanceList (clone); ilist.addThruPipe(new StringArrayIterator(data)); assertTrue (ilist.size() == 3); }
private void testSerializationForAlg (Inferencer alg) throws IOException, ClassNotFoundException { for (int mdlIdx = 0; mdlIdx < models.length; mdlIdx++) { FactorGraph mdl = models [mdlIdx]; // Copy the inferencer before calling b/c of random seed issues. Inferencer alg2 = (Inferencer) TestSerializable.cloneViaSerialization (alg); alg.computeMarginals(mdl); Factor[] pre = collectAllMarginals (mdl, alg); alg2.computeMarginals (mdl); Factor[] post2 = collectAllMarginals (mdl, alg2); compareMarginals ("Error comparing marginals after serialzation on model "+mdl, pre, post2); } }
private void testSerializationForAlg (Inferencer alg) throws IOException, ClassNotFoundException { for (int mdlIdx = 0; mdlIdx < models.length; mdlIdx++) { FactorGraph mdl = models [mdlIdx]; // Copy the inferencer before calling b/c of random seed issues. Inferencer alg2 = (Inferencer) TestSerializable.cloneViaSerialization (alg); alg.computeMarginals(mdl); Factor[] pre = collectAllMarginals (mdl, alg); alg2.computeMarginals (mdl); Factor[] post2 = collectAllMarginals (mdl, alg2); compareMarginals ("Error comparing marginals after serialzation on model "+mdl, pre, post2); } }
public void testFromSerialization () throws IOException, ClassNotFoundException { Pipe p = new GenericAcrfData2TokenSequence (); InstanceList training = new InstanceList (p); training.addThruPipe (new LineGroupIterator (new StringReader (sampleData), Pattern.compile ("^$"), true)); Pipe p2 = (Pipe) TestSerializable.cloneViaSerialization (p); InstanceList l1 = new InstanceList (p); l1.addThruPipe (new LineGroupIterator (new StringReader (sampleData2), Pattern.compile ("^$"), true)); InstanceList l2 = new InstanceList (p2); l2.addThruPipe (new LineGroupIterator (new StringReader (sampleData2), Pattern.compile ("^$"), true)); // the readResolve alphabet thing doesn't kick in on first deserialization assertTrue (p.getTargetAlphabet () != p2.getTargetAlphabet ()); assertEquals (1, l1.size ()); assertEquals (1, l2.size ()); Instance inst1 = l1.get (0); Instance inst2 = l2.get (0); LabelsSequence ls1 = (LabelsSequence) inst1.getTarget (); LabelsSequence ls2 = (LabelsSequence) inst2.getTarget (); assertEquals (4, ls1.size ()); assertEquals (4, ls2.size ()); for (int i = 0; i < 4; i++) { assertEquals (ls1.get (i).toString (), ls2.get (i).toString ()); } }
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 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 testFromSerialization () throws IOException, ClassNotFoundException { Pipe p = new GenericAcrfData2TokenSequence (); InstanceList training = new InstanceList (p); training.addThruPipe (new LineGroupIterator (new StringReader (sampleData), Pattern.compile ("^$"), true)); Pipe p2 = (Pipe) TestSerializable.cloneViaSerialization (p); InstanceList l1 = new InstanceList (p); l1.addThruPipe (new LineGroupIterator (new StringReader (sampleData2), Pattern.compile ("^$"), true)); InstanceList l2 = new InstanceList (p2); l2.addThruPipe (new LineGroupIterator (new StringReader (sampleData2), Pattern.compile ("^$"), true)); // the readResolve alphabet thing doesn't kick in on first deserialization assertTrue (p.getTargetAlphabet () != p2.getTargetAlphabet ()); assertEquals (1, l1.size ()); assertEquals (1, l2.size ()); Instance inst1 = l1.get (0); Instance inst2 = l2.get (0); LabelsSequence ls1 = (LabelsSequence) inst1.getTarget (); LabelsSequence ls2 = (LabelsSequence) inst2.getTarget (); assertEquals (4, ls1.size ()); assertEquals (4, ls2.size ()); for (int i = 0; i < 4; i++) { assertEquals (ls1.get (i).toString (), ls2.get (i).toString ()); } }
public void testSerialization () throws IOException, ClassNotFoundException { Assignment assn = new Assignment (vars, new int[] { 1, 0 }); Assignment assn2 = (Assignment) TestSerializable.cloneViaSerialization (assn); assertEquals (2, assn2.numVariables ()); assertEquals (1, assn2.numRows ()); assertEquals (1, assn.get (vars [0])); assertEquals (0, assn.get (vars [1])); }
public void testSerialization () throws IOException, ClassNotFoundException { Assignment assn = new Assignment (vars, new int[] { 1, 0 }); Assignment assn2 = (Assignment) TestSerializable.cloneViaSerialization (assn); assertEquals (2, assn2.numVariables ()); assertEquals (1, assn2.numRows ()); assertEquals (1, assn.get (vars [0])); assertEquals (0, assn.get (vars [1])); }