示例#1
0
    def test_cellref_basics(self) -> None:
        ca = StepCanvas([Step([4, 5, 6])])
        cr0 = CellRef(ca, 0)
        cr1 = CellRef(ca, 1)

        # StepCanvas[0]
        self.assertEqual(cr0.value, Step([4, 5, 6]))
        self.assertCountEqual(as_iter(cr0.avails), [4, 5, 6])
        taken, remaining = cr0.take_avails([4, 5])
        self.assertCountEqual(taken, [4, 5])
        self.assertCountEqual(remaining, [6])
        self.assertEqual(cr0.value, Step([4, 5, 6]))
        self.assertTrue(cr0.has_a_value())

        self.assertTrue(cr0.has_avail_value(4))
        self.assertFalse(cr0.has_avail_value(7))

        with self.assertRaises(ValuesNotAvail) as cm:
            taken, remaining = cr0.take_avails([4, 7])
        self.assertEqual(
            cm.exception,
            ValuesNotAvail(cellref=cr0, avails=(4, None), unavails=(None, 7)))

        #StepCanvas[1]
        self.assertEqual(cr1.value, None)
        self.assertFalse(cr1.has_a_value())
        self.assertCountEqual(as_iter(cr1.avails), [])
        with self.assertRaises(ValuesNotAvail) as cm:
            taken, remaining = cr1.take_avails([4, 7])
        self.assertEqual(
            cm.exception,
            ValuesNotAvail(cellref=cr1, avails=(4, 7), unavails=()))

        # paint
        cr1.paint(Step([6], StepDelta([4, 5], [9], '+')))
        self.assertEqual(ca[1], Step([6], StepDelta([4, 5], [9], '+')))
示例#2
0
文件: Canvas.py 项目: bkovitz/FARGish
 def consume(self, source: CellRef, operands: Sequence[Value]) -> Step:
     taken_avails, remaining_avails = source.take_avails(operands)
     result = self(*taken_avails)
     new_avails = tuple(remaining_avails) + (result, )
     delta = StepDelta(tuple(taken_avails), result, self)
     return Step(new_avails, delta)