def test_format_small_numbers(self): fmt = BasicFormatter() numlabels = 8 # test with small numbers scale = FixedScale(resolution=1e-4) start, end = 5e-5, 8.5e-4 ticks = scale.ticks(start, end, numlabels) labels = fmt.format(ticks, numlabels, None) desired = [str(float(i)) + "e-4" for i in range(1, 9)] self.check_labels(labels, desired)
def test_format_small_numbers(self): fmt = BasicFormatter() numlabels = 8 # test with small numbers scale = FixedScale(resolution = 1e-4) start, end = 5e-5, 8.5e-4 ticks = scale.ticks(start, end, numlabels) labels = fmt.format(ticks, numlabels, None) desired = [str(float(i))+"e-4" for i in range(1, 9)] self.check_labels(labels, desired)
def test_format(self): fmt = BasicFormatter() # test with a fixed scale scale = FixedScale(resolution=1.0) start, end = 12.0, 18.0 numlabels = 8 ticks = scale.ticks(start, end, numlabels) labels = fmt.format(ticks, numlabels, None) # desired = [str(float(x)) for x in range(12, 19)] ## This test fails when desired is created with str(float(x)). ## The format function returns "12",...,"18", not "12.0",...,"18.0". desired = ["12", "13", "14", "15", "16", "17", "18"] self.check_labels(labels, desired)
def test_format(self): fmt = BasicFormatter() # test with a fixed scale scale = FixedScale(resolution = 1.0) start, end = 12.0, 18.0 numlabels = 8 ticks = scale.ticks(start, end, numlabels) labels = fmt.format(ticks, numlabels, None) # desired = [str(float(x)) for x in range(12, 19)] ## This test fails when desired is created with str(float(x)). ## The format function returns "12",...,"18", not "12.0",...,"18.0". desired = ["12","13","14","15","16","17","18"] self.check_labels(labels, desired)
def test_estimate_default_scale(self): fmt = BasicFormatter() scale = DefaultScale() # Test using numlabels test_intervals = ((12., 18., 8), (-4., 16., 10), (5e-5, 8.5e-4, 8), (3e8, 6e8, 8), ) for start, end, numlabels in test_intervals: estimate = fmt.estimate_width(start, end, numlabels, ticker=scale)[1] ticks = scale.ticks(start, end, numlabels) labels = fmt.format(ticks, numlabels, None) actual = sum(map(len, labels)) err = abs(estimate - actual) / actual self.assertLess(err, 0.5) return
def test_estimate_default_scale(self): fmt = BasicFormatter() scale = DefaultScale() # Test using numlabels test_intervals = ((12., 18., 8), (-4., 16., 10), (5e-5, 8.5e-4, 8), (3e8, 6e8, 8), ) for start, end, numlabels in test_intervals: estimate = fmt.estimate_width(start, end, numlabels, ticker=scale)[1] ticks = scale.ticks(start, end, numlabels) labels = fmt.format(ticks, numlabels, None) actual = sum(map(len, labels)) err = abs(estimate - actual) / actual self.assertLess(err, 0.5) return