Пример #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)))
Пример #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))
Пример #3
0
    def test_integer(self):
        a = Cell()

        constant(5)(a)

        scheduler.run()

        self.assertEqual(a.content, 5)
Пример #4
0
    def test_integer(self):
        a = Cell()

        constant(5)(a)

        scheduler.run()

        self.assertEqual(a.content, 5)
Пример #5
0
    def test_false_to_true(self):
        a = Cell(content=False)
        b = Cell()

        inverter(a, b)

        scheduler.run()

        self.assertEqual(b.content, True)
Пример #6
0
    def test_false_to_true(self):
        a = Cell(content=False)
        b = Cell()

        inverter(a, b)

        scheduler.run()

        self.assertEqual(b.content, True)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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')
Пример #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)
Пример #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')
Пример #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)
Пример #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)
Пример #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)
Пример #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')
Пример #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)
Пример #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)
Пример #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)
Пример #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')
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #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()
Пример #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)