def test_scan1l_constraints(self): INTMIN = constraint.INTMIN INTMAX = constraint.INTMAX expectedmap = { impl.LPLUS: constraint.ListConstraint(1, 4, [constraint.IntConstraint()] + [ constraint.IntConstraint(int(INTMIN / l), int(INTMAX / l)) for l in range(1, 5) ]), impl.LMINUS: constraint.ListConstraint(1, 4, [constraint.IntConstraint()] + [ constraint.IntConstraint(int(INTMIN / l), int(INTMAX / l)) for l in range(1, 5) ]), impl.LTIMES: constraint.ListConstraint(1, 4, [constraint.IntConstraint()] + [ constraint.IntConstraint(-int(10**(np.log10(INTMAX) / l)), int(10**(np.log10(INTMAX) / l))) for l in range(1, 5) ]), } output_lc = constraint.ListConstraint(1, 4) for lmbda, expected in expectedmap.items(): stmt = impl.SCAN1L, (lmbda, 0) actual = constraint.get_constraints_from_stmt(stmt, output_lc)[0] self.assertEqual(expected, actual)
def test_clip(self): expectedmap = { impl.PLUS1: constraint.IntConstraint(-256, 255), } ic = constraint.IntConstraint() for lmbda, expected in expectedmap.items(): ics = [ic] * 4 lc = constraint.ListConstraint(1, 4, ics) stmt = impl.MAP, (lmbda, 0) lc1 = constraint.get_constraints_from_stmt(stmt, lc)[0] self.assertEqual(lc.lmin, lc1.lmin) self.assertEqual(lc.lmax, lc1.lmax) for ic1 in lc1.int_constraints: self.assertEqual(ic1, expected)
def test_zipwith_constraints(self): expectedmap = { impl.LPLUS: constraint.IntConstraint(-5, 2), impl.LMINUS: constraint.IntConstraint(-5, 2), impl.LTIMES: constraint.IntConstraint(-2, 2), } ic = constraint.IntConstraint(-10, 4) for lmbda, expected in expectedmap.items(): ics = [ic] * 4 expected_lc = constraint.ListConstraint(1, 4, ics) stmt = impl.ZIPWITH, (lmbda, 0, 1) actual_lcs = constraint.get_constraints_from_stmt( stmt, expected_lc) for actual_lc in actual_lcs: self.assertEqual(expected_lc.lmin, actual_lc.lmin) self.assertEqual(expected_lc.lmax, actual_lc.lmax) for actual_ic in actual_lc.int_constraints: self.assertEqual(actual_ic, expected)
def test_map_constraints(self): expectedmap = { impl.PLUS1: constraint.IntConstraint(-11, 3), impl.MINUS1: constraint.IntConstraint(-9, 5), impl.TIMES2: constraint.IntConstraint(-5, 2), impl.TIMES3: constraint.IntConstraint(-3, 1), impl.TIMES4: constraint.IntConstraint(-2, 1), impl.TIMESNEG1: constraint.IntConstraint(-4, 10), impl.POW2: constraint.IntConstraint(-2, 2) } ic = constraint.IntConstraint(-10, 4) for lmbda, expected in expectedmap.items(): ics = [ic] * 4 lc = constraint.ListConstraint(1, 4, ics) stmt = impl.MAP, (lmbda, 0) lc1 = constraint.get_constraints_from_stmt(stmt, lc)[0] self.assertEqual(lc.lmin, lc1.lmin) self.assertEqual(lc.lmax, lc1.lmax) for ic1 in lc1.int_constraints: self.assertEqual(ic1, expected)