def __init__(self): shape1, shape2, shape3 = sg.sample_shape(3) objs1 = tg.Select(shape=shape1, when='now') objs2 = tg.Select(shape=shape2, when='now') objs3 = tg.Select(shape=shape3, when=sg.random_when()) bool1 = tg.And(tg.Exist(objs1), tg.Exist(objs2)) self._operator = tg.Switch(bool1, tg.Go(objs1), tg.Go(objs3), both_options_avail=False)
def testSetChild(self): objs1 = tg.Select(when='last1') objs2 = tg.Select(when='now') s1 = tg.GetShape(objs1) s2 = tg.GetShape(objs2) c1 = tg.GetColor(objs1) c2 = tg.GetColor(objs2) and1 = tg.And(tg.IsSame(s1, s2), tg.IsSame(c1, c2)) self.assertEqual(len(and1.child), 2)
def __init__(self): color1, color2, color3 = sg.sample_color(3) objs1 = tg.Select(color=color1, when='now') objs2 = tg.Select(color=color2, when='now') objs3 = tg.Select(color=color3, when=sg.random_when()) bool1 = tg.And(tg.Exist(objs1), tg.Exist(objs2)) self._operator = tg.Switch(bool1, tg.Go(objs1), tg.Go(objs3), both_options_avail=False)
def testAndOperatorSize(self): objs1 = tg.Select(when='last1') objs2 = tg.Select(when='now') s1 = tg.GetShape(objs1) s2 = tg.GetShape(objs2) c1 = tg.GetColor(objs1) c2 = tg.GetColor(objs2) and1 = tg.And(tg.IsSame(s1, s2), tg.IsSame(c1, c2)) task = tg.Task(and1) self.assertEqual(task.operator_size, 9)
def __init__(self): color1, color2, color3, color4 = sg.sample_color(4) objs1 = tg.Select(color=color1, when=sg.random_when()) objs2 = tg.Select(color=color2, when=sg.random_when()) objs3 = tg.Select(color=color3, when=sg.random_when()) objs4 = tg.Select(color=color4, when=sg.random_when()) a1 = tg.GetShape(objs1) a2 = tg.GetShape(objs2) a3 = tg.GetShape(objs3) a4 = tg.GetShape(objs4) self._operator = tg.And(tg.IsSame(a1, a2), tg.IsSame(a3, a4))
def __init__(self): shape1, shape2, shape3, shape4 = sg.sample_shape(4) objs1 = tg.Select(shape=shape1, when=sg.random_when()) objs2 = tg.Select(shape=shape2, when=sg.random_when()) objs3 = tg.Select(shape=shape3, when=sg.random_when()) objs4 = tg.Select(shape=shape4, when=sg.random_when()) a1 = tg.GetColor(objs1) a2 = tg.GetColor(objs2) a3 = tg.GetColor(objs3) a4 = tg.GetColor(objs4) self._operator = tg.And(tg.IsSame(a1, a2), tg.IsSame(a3, a4))
def __init__(self): attr1, attr2, attr3 = sg.sample_colorshape(3) objs1 = tg.Select(color=attr1[0], shape=attr1[1], when='now') objs2 = tg.Select(color=attr2[0], shape=attr2[1], when='now') objs3 = tg.Select(color=attr3[0], shape=attr3[1], when=sg.random_when()) bool1 = tg.And(tg.Exist(objs1), tg.Exist(objs2)) self._operator = tg.Switch(bool1, tg.Go(objs1), tg.Go(objs3), both_options_avail=False)
def testOperatorSize(self): objs1 = tg.Select(shape=sg.Shape('circle'), when='now') color1 = tg.GetColor(objs1) objs2 = tg.Select(color=color1, shape=sg.Shape('square'), when='now') exist = tg.Exist(objs2) task = tg.Task(exist) self.assertEqual(task.operator_size, 4) objs1 = tg.Select(when='last1') objs2 = tg.Select(when='now') s1 = tg.GetShape(objs1) s2 = tg.GetShape(objs2) c1 = tg.GetColor(objs1) c2 = tg.GetColor(objs2) bool1 = tg.And(tg.IsSame(s1, s2), tg.IsSame(c1, c2)) task = tg.Task(bool1) self.assertEqual(task.operator_size, 9)
def __init__(self): color1, color2 = sg.sample_color(2) objs1 = tg.Select(color=color1, when=sg.random_when()) objs2 = tg.Select(color=color2, when=sg.random_when()) shape11 = tg.GetShape(objs1) shape21 = tg.GetShape(objs2) shape12, shape22 = sg.random_shape(), sg.random_shape() if random.random() > 0.5: bool1 = tg.IsSame(shape11, shape12) else: bool1 = tg.IsSame(shape11, shape12) if random.random() > 0.5: bool2 = tg.IsSame(shape21, shape22) else: bool2 = tg.IsSame(shape21, shape22) self._operator = tg.And(bool1, bool2)
def __init__(self): shape1, shape2 = sg.sample_shape(2) objs1 = tg.Select(shape=shape1, when=sg.random_when()) objs2 = tg.Select(shape=shape2, when=sg.random_when()) color11 = tg.GetColor(objs1) color21 = tg.GetColor(objs2) color12, color22 = sg.random_color(), sg.random_color() if random.random() > 0.5: bool1 = tg.IsSame(color11, color12) else: bool1 = tg.IsSame(color11, color12) if random.random() > 0.5: bool2 = tg.IsSame(color21, color22) else: bool2 = tg.IsSame(color21, color22) self._operator = tg.And(bool1, bool2)
def testAndCompareColorGuessObjset(self): objs1 = tg.Select(shape=sg.Shape('circle'), when='last1') objs2 = tg.Select(shape=sg.Shape('square'), when='last1') objs3 = tg.Select(shape=sg.Shape('triangle'), when='last1') objs4 = tg.Select(shape=sg.Shape('hbar'), when='last1') a1 = tg.Get('color', objs1) a2 = tg.Get('color', objs2) a3 = tg.Get('color', objs3) a4 = tg.Get('color', objs4) task = tg.Task(tg.And(tg.IsSame(a1, a2), tg.IsSame(a3, a4))) n_epoch = 10 for i in range(100): epoch_now = random.randint(1, n_epoch - 1) objset = sg.ObjectSet(n_epoch=n_epoch) should_be = random.random() > 0.5 objset = task.guess_objset(objset, epoch_now, should_be=should_be) self.assertEqual(task(objset, epoch_now), should_be)
def testAndGuessObjset(self): objs1 = tg.Select(when='last1') objs2 = tg.Select(when='now') s1 = tg.GetShape(objs1) s2 = tg.GetShape(objs2) c1 = tg.GetColor(objs1) c2 = tg.GetColor(objs2) task = tg.Task(tg.And(tg.IsSame(s1, s2), tg.IsSame(c1, c2))) objset = sg.ObjectSet(n_epoch=10) obj0 = sg.Object([sg.Color('green'), sg.Shape('square')], when='now') obj1 = sg.Object([sg.Color('red'), sg.Shape('circle')], when='now') objset.add(obj0, epoch_now=0) objset.add(obj1, epoch_now=1) objset = task.guess_objset(objset, epoch_now=2, should_be=True) obj2 = objset.last_added_obj self.assertEqual(obj1.color.value, obj2.color.value) self.assertEqual(obj1.shape.value, obj2.shape.value)