def test_delta_sign(self): """Delta class sign. """ d = Delta("+-") self.assertEquals(d.cmp(0, 1), False) self.assertEquals(d.cmp(-1, 0), False) self.assertEquals(d.cmp(-1, 1), True)
def test_delta_val(self): """Delta class value, same absolute equality. """ d = Delta("+-3.0=") self.assertEquals(d.cmp(0, 1), False) self.assertEquals(d.cmp(1, 4), True) self.assertEquals(d.cmp(4, 1), True)
def test_delta_val(self): """Delta class value, same percentage equality. """ d = Delta("+-25=%") self.assertEquals(d.cmp(0, 1), False) self.assertEquals(d.cmp(8, 4), True) self.assertEquals(d.cmp(8, 6), True)
def test_delta_val(self): """Delta class value, different absolute. """ d = Delta("+2.5-1.5") self.assertEquals(d.cmp(0, 1), False) self.assertEquals(d.cmp(1, 3), False) self.assertEquals(d.cmp(3, 1), True)
def test_delta_val(self): """Delta class value, same absolute. """ d = Delta("+-3") self.assertEqual(d.cmp(0, 1), False) self.assertEqual(d.cmp(1, 4), False) self.assertEqual(d.cmp(1, 5), True)
def test_delta_val(self): """Delta class value, different percentage equality. """ d = Delta("+50-25=%") self.assertEquals(d.cmp(0, 1), False) self.assertEquals(d.cmp(8, 4), True) self.assertEquals(d.cmp(8, 6), True) self.assertEquals(d.cmp(6, 8), False) self.assertEquals(d.cmp(6, 9), True)
def test_delta_minus(self): """Delta class value 'minus only'. """ d = Delta("-50") self.assertEquals(d.cmp(0, 50), False) self.assertEquals(d.cmp(51, 0), True) self.assertEquals(d.cmp(5, 10), False) d = Delta("-50=") self.assertEquals(d.cmp(50, 0), True) d = Delta("-50%") self.assertEquals(d.cmp(25, 10), True) self.assertEquals(d.cmp(10, 25), False)
def test_delta_plus(self): """Delta class value 'plus only'. """ d = Delta("+50") self.assertEquals(d.cmp(0, 50), False) self.assertEquals(d.cmp(0, 51), True) self.assertEquals(d.cmp(10, 5), False) d = Delta("+50=") self.assertEquals(d.cmp(0, 50), True) d = Delta("+50%") self.assertEquals(d.cmp(10, 25), True) self.assertEquals(d.cmp(25, 10), False)
def test_numprops_different_pct(self): """Keys and props, some props different, check pct change. """ # Perform diff. minus, plus = 10, 20 df = Differ(key='name', deltas={"energy": Delta("+{}-{}=%".format(plus, minus))}) d = df.diff(*self.engines) # Calculate expected results. def is_different(a, b): pct = 100.0 * (b - a) / a return pct <= -minus or pct >= plus changed = sum((int(is_different(e[0], e[1])) for e in self.energies)) # Check results. if len(d[Differ.CHANGED]) != changed: result = d[Differ.CHANGED] msg = "Values:\n" for i, e in enumerate(self.energies): if not is_different(*e): continue msg += "{:d}) {:f} {:f}\n".format(i, e[0], e[1]) msg += "Result:\n" for i, r in enumerate(result): msg += "{:d}) {} {}\n".format(i, r["old"], r["new"]) self.assertEqual(len(d[Differ.CHANGED]), changed, msg=msg)
def test_numprops_same(self): """Keys and props, all are the same. """ # Perform diff. df = Differ(key='name', deltas={"zero": Delta("+-0.001")}) d = df.diff(*self.engines) # Check results. self.assertEqual(len(d[Differ.CHANGED]), 0)
def test_numprops_different_sign(self): """Keys and props, some props different. """ # Perform diff. df = Differ(key='name', deltas={"energy": Delta("+-")}) d = df.diff(*self.engines) # Calculate expected results. is_different = lambda a, b: a < 0 < b or b < 0 < a changed = sum((int(is_different(e[0], e[1])) for e in self.energies)) # Check results. self.assertEqual(len(d[Differ.CHANGED]), changed)