def test_units_inputs(self):
        # Stolen from FBX addon!
        def similar_values(v1, v2, e):
            if v1 == v2:
                return True
            return ((abs(v1 - v2) / max(abs(v1), abs(v2))) <= e)

        for usys, utype, ref, inpt, val in self.INPUT_TESTS:
            opt_val = units.to_value(usys, utype, inpt, ref)
            # Note: almostequal is not good here, precision is fixed on decimal digits, not variable with
            # magnitude of numbers (i.e. 1609.4416 ~= 1609.4456 fails even at 5 of 'places'...).
            self.assertTrue(similar_values(opt_val, val, 1e-7),
                            msg="%s, %s: \"%s\" (ref: \"%s\") => %f, expected %f"
                                "" % (usys, utype, inpt, ref, opt_val, val))
Esempio n. 2
0
    def test_units_inputs(self):
        # Stolen from FBX addon!
        def similar_values(v1, v2, e):
            if v1 == v2:
                return True
            return ((abs(v1 - v2) / max(abs(v1), abs(v2))) <= e)

        for usys, utype, ref, inpt, val in self.INPUT_TESTS:
            opt_val = units.to_value(usys, utype, inpt, str_ref_unit=ref)
            # Note: almostequal is not good here, precision is fixed on decimal digits, not variable with
            # magnitude of numbers (i.e. 1609.4416 ~= 1609.4456 fails even at 5 of 'places'...).
            self.assertTrue(similar_values(opt_val, val, 1e-7),
                            msg="%s, %s: \"%s\" (ref: \"%s\") => %f, expected %f"
                                "" % (usys, utype, inpt, ref, opt_val, val))