def test_my_inputs(self): values = VariableTestToolbox().compute_variable(self.variable_name, {"zone":{ "zone_id":array([1,2])}, "travel_data":{ "from_zone_id":array([1,1,2,2]), "to_zone_id":array([1,2,1,2]), self.time_attribute_name:array([1.1, 2.2, 3.3, 4.4]), self.trips_attribute_name:array([1.0, 2.0, 3.0, 4.0])}}, dataset = "zone", package=package()) should_be = array([(1.1*1.0 +2.2*2.0)/(3.0), (3.3*3.0 + 4.4*4.0)/(7.0)]) self.assert_(ma.allclose(values, should_be, rtol=1e-4), "Error in " + self.variable_name)
def test_with_zero_denominator(self): values = VariableTestToolbox().compute_variable(self.variable_name, {"zone":{ "zone_id":array([1,2,3,4])}, "travel_data":{ "from_zone_id":array([1,2,2,3,4]), "to_zone_id":array([1,2,1,2,2]), self.time_attribute_name:array([1.1, 2.2, 3.3, 4.4, 5.5]), self.trips_attribute_name:array([10.1, 20.0, 30.0, 0.0, 0.0])}}, dataset = "zone", package=package()) should_be = array([(1.1*10.1)/(10.1), (2.2*20.0 + 3.3*30)/(20.0+30.0), (2.2*20.0 + 3.3*30)/(20.0+30.0),# when denominator = 0, use prior good value (2.2*20.0 + 3.3*30)/(20.0+30.0)])# when denominator = 0, use prior good value self.assert_(ma.allclose(values, should_be, rtol=1e-4), "Error in " + self.variable_name)