Example #1
0
 def test_multiplier_interval(self):
     c1 = Cell(content=Supported(Interval(3, 4)))
     c2 = Cell(content=Supported(Interval(5, 6)))
     c3 = Cell()
     multiplier(c1, c2, c3)
     scheduler.run()
     self.assertEqual(c3.content, Supported(Interval(15, 24)))
Example #2
0
 def test_multiplier_exact(self):
     c1 = Cell(content=Supported(3))
     c2 = Cell(content=Supported(4))
     c3 = Cell()
     multiplier(c1, c2, c3)
     scheduler.run()
     self.assertEqual(c3.content, Supported(12))
Example #3
0
    def test_integer(self):
        a = Cell()

        constant(5)(a)

        scheduler.run()

        self.assertEqual(a.content, 5)
Example #4
0
    def test_integer(self):
        a = Cell()

        constant(5)(a)

        scheduler.run()

        self.assertEqual(a.content, 5)
Example #5
0
    def test_false_to_true(self):
        a = Cell(content=False)
        b = Cell()

        inverter(a, b)

        scheduler.run()

        self.assertEqual(b.content, True)
Example #6
0
    def test_false_to_true(self):
        a = Cell(content=False)
        b = Cell()

        inverter(a, b)

        scheduler.run()

        self.assertEqual(b.content, True)
Example #7
0
    def test_integer_false(self):
        a = Cell(content=13)
        b = Cell(content=15)
        c = Cell()

        greater_than(a, b, c)

        scheduler.run()

        self.assertEqual(c.content, False)
Example #8
0
    def test_integer_true(self):
        a = Cell(content=17)
        b = Cell(content=15)
        c = Cell()

        greater_than(a, b, c)

        scheduler.run()

        self.assertEqual(c.content, True)
Example #9
0
    def test_false(self):
        a = Cell(content=False)
        b = Cell(content='yes')
        c = Cell()

        switch(a, b, c)

        scheduler.run()

        self.assertEqual(c.content, None)
Example #10
0
    def test_integer_true(self):
        a = Cell(content=17)
        b = Cell(content=15)
        c = Cell()

        greater_than(a, b, c)

        scheduler.run()

        self.assertEqual(c.content, True)
Example #11
0
    def test_integer_false(self):
        a = Cell(content=13)
        b = Cell(content=15)
        c = Cell()

        greater_than(a, b, c)

        scheduler.run()

        self.assertEqual(c.content, False)
Example #12
0
    def test_true(self):
        a = Cell(content=True)
        b = Cell(content='yes')
        c = Cell()

        switch(a, b, c)

        scheduler.run()

        self.assertEqual(c.content, 'yes')
Example #13
0
    def test_false(self):
        a = Cell(content=False)
        b = Cell(content='yes')
        c = Cell()

        switch(a, b, c)

        scheduler.run()

        self.assertEqual(c.content, None)
Example #14
0
    def test_true(self):
        a = Cell(content=True)
        b = Cell(content='yes')
        c = Cell()

        switch(a, b, c)

        scheduler.run()

        self.assertEqual(c.content, 'yes')
Example #15
0
    def test_integer(self):
        a = Cell()
        b = Cell()
        c = Cell()

        multiplier(a, b, c)

        a.add_content(5)
        b.add_content(3)

        scheduler.run()

        self.assertEqual(c.content, 15)
Example #16
0
    def test_integer(self):
        a = Cell()
        b = Cell()
        c = Cell()

        divider(a, b, c)

        a.add_content(9)
        b.add_content(3)

        scheduler.run()

        self.assertEqual(c.content, 3)
Example #17
0
    def test_integer(self):
        a = Cell()
        b = Cell()
        c = Cell()

        subtractor(a, b, c)

        a.add_content(15)
        b.add_content(13)

        scheduler.run()

        self.assertEqual(c.content, 2)
Example #18
0
    def test_str(self):
        a = Cell()
        b = Cell()
        c = Cell()

        adder(a, b, c)

        a.add_content('15')
        b.add_content('13')

        scheduler.run()

        self.assertEqual(c.content, '1513')
Example #19
0
    def test_float(self):
        a = Cell()
        b = Cell()
        c = Cell()

        adder(a, b, c)

        a.add_content(1.5)
        b.add_content(1.3)

        scheduler.run()

        self.assertEqual(c.content, 2.8)
Example #20
0
    def test_integer(self):
        a = Cell()
        b = Cell()
        c = Cell()

        multiplier(a, b, c)

        a.add_content(5)
        b.add_content(3)

        scheduler.run()

        self.assertEqual(c.content, 15)
Example #21
0
    def test_integer(self):
        a = Cell()
        b = Cell()
        c = Cell()

        subtractor(a, b, c)

        a.add_content(15)
        b.add_content(13)

        scheduler.run()

        self.assertEqual(c.content, 2)
Example #22
0
    def test_str(self):
        a = Cell()
        b = Cell()
        c = Cell()

        adder(a, b, c)

        a.add_content('15')
        b.add_content('13')

        scheduler.run()

        self.assertEqual(c.content, '1513')
Example #23
0
    def test_float(self):
        a = Cell()
        b = Cell()
        c = Cell()

        adder(a, b, c)

        a.add_content(1.5)
        b.add_content(1.3)

        scheduler.run()

        self.assertEqual(c.content, 2.8)
Example #24
0
    def test_integer(self):
        a = Cell()
        b = Cell()
        c = Cell()

        divider(a, b, c)

        a.add_content(9)
        b.add_content(3)

        scheduler.run()

        self.assertEqual(c.content, 3)
Example #25
0
    def test_integer(self):
        a = Cell()
        b = Cell()

        a_ = Cell()
        b_ = Cell()

        absolute_value(a, b)
        absolute_value(a_, b_)

        a.add_content(-9)
        a_.add_content(9)

        scheduler.run()

        self.assertEqual(b.content, 9)
        self.assertEqual(b_.content, 9)
Example #26
0
    def test_integer(self):
        a = Cell()
        b = Cell()

        a_ = Cell()
        b_ = Cell()

        absolute_value(a, b)
        absolute_value(a_, b_)

        a.add_content(-9)
        a_.add_content(9)

        scheduler.run()

        self.assertEqual(b.content, 9)
        self.assertEqual(b_.content, 9)
Example #27
0
    # How do we want our provenance system to work? We can make cells
    # and define networks as usual, but if we add supported values as inputs,
    # we get supported values as outputs:

    barometer_height = Cell('barometer height')
    barometer_shadow = Cell('barometer shadow')
    building_height = Cell('building height')
    building_shadow = Cell('building shadow')

    similar_triangles(barometer_shadow, barometer_height, building_shadow, building_height)

    building_shadow.add_content(Supported(Interval(54.9, 55.1), ['shadows']))
    barometer_height.add_content(Supported(Interval(0.3, 0.32), ['shadows']))
    barometer_shadow.add_content(Supported(Interval(0.36, 0.37), ['shadows']))

    scheduler.run()

    print(building_height.content)
    # Supported(Interval(44.51351351351351, 48.977777777777774), {'shadows'})

    # Indeed, our estimate for the height of the building depends on our
    # measurements of the barometer and the shadow. We can try
    # dropping the barometer off the roof, but if we do a bad job of
    # timing its fall, our estimate won’t improve.

    fall_time = Cell('fall time')
    fall_duration(fall_time, building_height)
    fall_time.add_content(Supported(Interval(2.9, 3.3), {'lousy fall time'}))

    scheduler.run()
Example #28
0
defined in this module.
"""
def good_enuf(g, x, done):
    @compound(neighbors=[g, x])
    def to_do():
        g_to_2 = Cell('g^2')
        x_minus_g_to_2 = Cell('x-g^2')
        ax_minus_g_to_2 = Cell('abs(x-g^2)')

        multiplier(g, g, g_to_2)
        subtractor(x, g_to_2, x_minus_g_to_2)
        absolute_value(x_minus_g_to_2, ax_minus_g_to_2)
        less_than(ax_minus_g_to_2, eps, done)

    return to_do


if __name__ == '__main__':
    scheduler.initialize()

    x = Cell('x')
    answer = Cell('answer')

    sqrt_network(x, answer)

    x.add_content(2)

    scheduler.run()

    print(answer.content)