Пример #1
0
 def test_set(self):
     from grease.component.field import FieldAccessor
     entities = set([3, 7, 8])
     comp = TestComponent()
     for i in range(9):
         comp[i] = TestData(id=i, xy=TestData(x=i * 10, y=i * -10))
     id_accessor = FieldAccessor(TestField(comp, 'id'), entities)
     xy_accessor = FieldAccessor(TestField(comp, 'xy'), entities)
     id_accessor.__set__(10)
     xy_accessor.x = 0
     for i in range(9):
         if i in entities:
             self.assertEqual(comp[i].id, 10)
             self.assertEqual(comp[i].xy.x, 0)
             self.assertEqual(comp[i].xy.y, i * -10)
         else:
             self.assertEqual(comp[i].id, i)
             self.assertEqual(comp[i].xy.x, i * 10)
             self.assertEqual(comp[i].xy.y, i * -10)
Пример #2
0
	def test_set(self):
		from grease.component.field import FieldAccessor
		entities = set([3,7,8])
		comp = TestComponent()
		for i in range(9):
			comp[i] = TestData(id=i, xy=TestData(x=i*10, y=i*-10))
		id_accessor = FieldAccessor(TestField(comp, 'id'), entities)
		xy_accessor = FieldAccessor(TestField(comp, 'xy'), entities)
		id_accessor.__set__(10)
		xy_accessor.x = 0
		for i in range(9):
			if i in entities:
				self.assertEqual(comp[i].id, 10)
				self.assertEqual(comp[i].xy.x, 0)
				self.assertEqual(comp[i].xy.y, i*-10)
			else:
				self.assertEqual(comp[i].id, i)
				self.assertEqual(comp[i].xy.x, i*10)
				self.assertEqual(comp[i].xy.y, i*-10)
Пример #3
0
	def test_set_join(self):
		from grease.component.field import FieldAccessor
		entities1 = set([2,3,7,8])
		entities2 = set([1,2,3])
		comp1 = TestComponent()
		comp2 = TestComponent()
		for i in range(9):
			comp1[i] = TestData(foo=i)
			comp2[i] = TestData(bar=-i)
		foo_accessor = FieldAccessor(TestField(comp1, 'foo'), entities1)
		bar_accessor = FieldAccessor(TestField(comp2, 'bar'), entities2)
		foo_accessor.__set__(bar_accessor)
		for i in range(9):
			if i in entities1 & entities2:
				self.assertEqual(comp1[i].foo, -i)
			else:
				self.assertEqual(comp1[i].foo, i)
			self.assertEqual(comp2[i].bar, -i)
		bar_accessor = FieldAccessor(TestField(comp2, 'bar'), entities1)
		foo_accessor.__set__(bar_accessor)
		for i in range(9):
			if i in entities1:
				self.assertEqual(comp1[i].foo, -i)
			else:
				self.assertEqual(comp1[i].foo, i)
			self.assertEqual(comp2[i].bar, -i)
		bar_accessor.__set__(foo_accessor)
		for i in range(9):
			if i in entities1:
				self.assertEqual(comp1[i].foo, comp2[i].bar)
			else:
				self.assertEqual(comp1[i].foo, i)
				self.assertEqual(comp2[i].bar, -i)
Пример #4
0
 def test_set_join(self):
     from grease.component.field import FieldAccessor
     entities1 = set([2, 3, 7, 8])
     entities2 = set([1, 2, 3])
     comp1 = TestComponent()
     comp2 = TestComponent()
     for i in range(9):
         comp1[i] = TestData(foo=i)
         comp2[i] = TestData(bar=-i)
     foo_accessor = FieldAccessor(TestField(comp1, 'foo'), entities1)
     bar_accessor = FieldAccessor(TestField(comp2, 'bar'), entities2)
     foo_accessor.__set__(bar_accessor)
     for i in range(9):
         if i in entities1 & entities2:
             self.assertEqual(comp1[i].foo, -i)
         else:
             self.assertEqual(comp1[i].foo, i)
         self.assertEqual(comp2[i].bar, -i)
     bar_accessor = FieldAccessor(TestField(comp2, 'bar'), entities1)
     foo_accessor.__set__(bar_accessor)
     for i in range(9):
         if i in entities1:
             self.assertEqual(comp1[i].foo, -i)
         else:
             self.assertEqual(comp1[i].foo, i)
         self.assertEqual(comp2[i].bar, -i)
     bar_accessor.__set__(foo_accessor)
     for i in range(9):
         if i in entities1:
             self.assertEqual(comp1[i].foo, comp2[i].bar)
         else:
             self.assertEqual(comp1[i].foo, i)
             self.assertEqual(comp2[i].bar, -i)