Exemplo n.º 1
0
 def Tester(test, category):
     for p in positive:
         obj = PSObjectFromStructure(p)
         test.assertTrue(
             obj.DescribeAs(category),
             "Describing %s as %s" % (obj.Structure(), category.BriefLabel()))
     for n in negative:
         obj = PSObjectFromStructure(n)
         test.assertFalse(
             obj.DescribeAs(category),
             "Describing %s as %s" % (obj.Structure(), category.BriefLabel()))
Exemplo n.º 2
0
    def test_extra_attribs(self):
        c1 = CategoryEvenInteger()
        o1 = PSObjectFromStructure(4)
        l = o1.DescribeAs(c1)
        self.assertTrue(l)
        self.assertNotIn('half', l.Attributes(), "No attribute 'half' yet")

        c1.TurnOnAttribute('half')
        o2 = PSObjectFromStructure(6)
        l2 = o2.DescribeAs(c1)
        self.assertTrue(l2)
        self.assertIn('half', l2.Attributes(), "Attribute 'half' now present")
        self.assertEqual(3, l2.GetAttributeOrNone(attribute='half').magnitude)
Exemplo n.º 3
0
    def test_categories_on_logic(self):
        c1 = C.RepeatedIntegerCategory()
        o1 = PSObjectFromStructure((7, 7))
        self.assertTrue(o1.DescribeAs(c1))
        self.assertTrue(o1.IsKnownAsInstanceOf(c1))

        logic = o1.DescribeAs(c1)
        logic.Attributes()['magnitude'].DescribeAs(CategoryPrime())
        self.assertTrue(logic.Attributes()['magnitude'].IsKnownAsInstanceOf(
            CategoryPrime()))

        # Get it again, see that the inner categorization has "stuck".
        logic = o1.DescribeAs(c1)
        self.assertTrue(logic.Attributes()['magnitude'].IsKnownAsInstanceOf(
            CategoryPrime()))
Exemplo n.º 4
0
    def test_group_insertion_deeper(self):
        """Make sure deeper features of the logic get copied."""

        arena = PSArena(magnitudes=(7, 8))

        gp = PSObjectFromStructure((7, 8))
        logic = gp.DescribeAs(BasicSuccessorCategory())

        CategoryEvenInteger().TurnOnAttribute('half')
        gp.items[1].DescribeAs(CategoryEvenInteger()).Attributes()[
            'half'].DescribeAs(CategoryEvenInteger())

        inner_logic = logic.Attributes()['end'].DescribeAs(
            CategoryEvenInteger())
        self.assertEqual(4, inner_logic.Attributes()['half'].magnitude)
        inner_logic.Attributes()['half'].DescribeAs(CategoryEvenInteger())

        CategoryEvenInteger().TurnOffAttribute('half')

        gp.SetSpanStart(0)
        merged = arena.MergeObject(gp)
        self.assertEqual((7, 8), merged.Structure())
        self.assertEqual(arena.element[1], merged.items[1])

        self.assertTrue(arena.element[1].IsKnownAsInstanceOf(
            CategoryEvenInteger()))
        logic = arena.element[1].categories[CategoryEvenInteger()]
        self.assertTrue(logic.Attributes()[
                        'half'].IsKnownAsInstanceOf(CategoryEvenInteger()))

        self.assertTrue(merged.DescribeAs(BasicSuccessorCategory()).Attributes()[
                        'end'].IsKnownAsInstanceOf(CategoryEvenInteger()))
Exemplo n.º 5
0
    def test_affordance(self):
        """What codelets does this suggest? It can own the relevant codelet families...

    This test is currently very speculative, as I try to firm up the interface a bit."""
        c1 = C.RepeatedIntegerCategory()
        o1 = PSObjectFromStructure((7, 7))
        self.assertTrue(o1.DescribeAs(c1))

        affordances = c1.GetAffordanceForInstance(o1)
        self.assertTrue(affordances)  # This is currently fake...