PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/interpreter/tags/at_build150307/test/edu/vub/at/objects/natives/StripesTest.java

http://ambienttalk.googlecode.com/
Java | 103 lines | 51 code | 18 blank | 34 comment | 0 complexity | 75d0dbef953a1487940652116d486c1c MD5 | raw file
  1package edu.vub.at.objects.natives;
  2
  3import edu.vub.at.AmbientTalkTest;
  4import edu.vub.at.eval.Evaluator;
  5import edu.vub.at.exceptions.InterpreterException;
  6import edu.vub.at.objects.ATObject;
  7import edu.vub.at.objects.ATStripe;
  8import edu.vub.at.objects.natives.grammar.AGSymbol;
  9
 10/**
 11 * Tests stripe definition, tagging, checking.
 12 * 
 13 * @author tvcutsem
 14 */
 15public class StripesTest extends AmbientTalkTest {
 16
 17	// test fixture
 18	
 19	// defstripe A <: stripe;
 20	private NATStripe stripeA_ = NATStripe.atValue(AGSymbol.jAlloc("A"), NATTable.EMPTY);
 21
 22	// defstripe B <: A;
 23	private NATStripe stripeB_ = NATStripe.atValue(AGSymbol.jAlloc("B"),
 24			NATTable.atValue(new ATObject[] { stripeA_ }));
 25	
 26	// defstripe C <: A;
 27	private NATStripe stripeC_ = NATStripe.atValue(AGSymbol.jAlloc("C"),
 28			NATTable.atValue(new ATObject[] { stripeA_ }));
 29	
 30	// defstripe D <: B, C;
 31	private NATStripe stripeD_ = NATStripe.atValue(AGSymbol.jAlloc("D"),
 32			NATTable.atValue(new ATObject[] { stripeB_, stripeC_ }));
 33	
 34	// object: { nil } stripedWith: [ B ]
 35	private NATObject striped_ = new NATObject(Evaluator.getGlobalLexicalScope(), new ATStripe[] { stripeB_ });
 36	
 37	// stripes defined without parent have the root stripe as single parent
 38	
 39	public void testParentlessStripe() throws InterpreterException {
 40		assertTrue(stripeA_.base_getParentStripes().base_getLength().equals(NATNumber.ONE));
 41		
 42		ATStripe root = stripeA_.base_getParentStripes().base_at(NATNumber.ONE).asStripe();
 43		assertEquals(NATStripe.OBJRootStripe._INSTANCE_, root);
 44	}
 45	
 46	// stripe subtyping:
 47	
 48	public void testPositiveSubstriping() throws InterpreterException {
 49		ATStripe root = NATStripe.OBJRootStripe._INSTANCE_;
 50        // root <: root
 51		assertTrue(root.base_isSubstripeOf(root).asNativeBoolean().javaValue);
 52        // A <: A
 53		assertTrue(stripeA_.base_isSubstripeOf(stripeA_).asNativeBoolean().javaValue);
 54		// A <: root
 55		assertTrue(stripeA_.base_isSubstripeOf(root).asNativeBoolean().javaValue);
 56		// B <: A
 57		assertTrue(stripeB_.base_isSubstripeOf(stripeA_).asNativeBoolean().javaValue);
 58		// D <: B
 59		assertTrue(stripeD_.base_isSubstripeOf(stripeB_).asNativeBoolean().javaValue);
 60		// D <: C
 61		assertTrue(stripeD_.base_isSubstripeOf(stripeC_).asNativeBoolean().javaValue);
 62		// D <: A
 63		assertTrue(stripeD_.base_isSubstripeOf(stripeA_).asNativeBoolean().javaValue);
 64		// D <: root
 65		assertTrue(stripeD_.base_isSubstripeOf(root).asNativeBoolean().javaValue);
 66	}
 67	
 68	public void testNegativeSubstriping() throws InterpreterException {
 69		ATStripe root = NATStripe.OBJRootStripe._INSTANCE_;
 70        // root <: A
 71		assertFalse(root.base_isSubstripeOf(stripeA_).asNativeBoolean().javaValue);
 72        // A <: D
 73		assertFalse(stripeA_.base_isSubstripeOf(stripeD_).asNativeBoolean().javaValue);
 74		// A <: B
 75		assertFalse(stripeA_.base_isSubstripeOf(stripeB_).asNativeBoolean().javaValue);
 76		// B <: C
 77		assertFalse(stripeB_.base_isSubstripeOf(stripeC_).asNativeBoolean().javaValue);
 78		// C <: B
 79		assertFalse(stripeC_.base_isSubstripeOf(stripeB_).asNativeBoolean().javaValue);
 80		// B <: D
 81		assertFalse(stripeB_.base_isSubstripeOf(stripeD_).asNativeBoolean().javaValue);
 82	}
 83	
 84	// object stripe testing:
 85	
 86	public void testObjectStripes() throws InterpreterException {
 87		// is: striped_ stripedWith: B => true
 88		assertTrue(striped_.meta_isStripedWith(stripeB_).asNativeBoolean().javaValue);
 89		// is: striped_ stripedWith: A => true
 90		assertTrue(striped_.meta_isStripedWith(stripeA_).asNativeBoolean().javaValue);
 91		// is: striped_ stripedWith: D => false
 92		assertFalse(striped_.meta_isStripedWith(stripeD_).asNativeBoolean().javaValue);
 93		// is: striped_ stripedWith: root => true
 94		assertTrue(striped_.meta_isStripedWith(NATStripe.OBJRootStripe._INSTANCE_).asNativeBoolean().javaValue);
 95		// is: striped_ stripedWith: C => false
 96		assertFalse(striped_.meta_isStripedWith(stripeC_).asNativeBoolean().javaValue);
 97		
 98	    // negative test: object has no stripes
 99		NATObject nostripes = new NATObject();
100		assertFalse(nostripes.meta_isStripedWith(stripeB_).asNativeBoolean().javaValue);
101	}
102	
103}