def test_scale_system(self): scale = ScaleSystem(FixedScale(resolution=1.0), FixedScale(resolution=2.5), FixedScale(resolution=5.0), FixedScale(resolution=10.0), FixedScale(resolution=20.0), FixedScale(resolution=100.0)) test_intervals = ( (1, 100, 200), (1, 100, 80), (1, 100, 40), (1, 100, 20), (1, 100, 5), (1, 10, 100), (1, 10, 50), (1, 10, 20), ) print for start, end, width in test_intervals: labels = scale.labels(start, end, char_width=width) print "(%d,%d)" % (start, end), " avail:", width, print " used:", sum([len(x[1]) for x in labels]), print zip(*labels)[1] return
def test_revert_to_default(self): scales = [FixedScale(resolution = 1.0), FixedScale(resolution = 10.0), FixedScale(resolution = 100.0)] ticker = ScaleSystem(*scales) ticks = ticker.ticks(2.0, 3.0, 10) self.check_ticks(ticks, frange(2.0, 3.0, 0.1))
def test_fixed_scales(self): scales = [FixedScale(resolution = 1.0), FixedScale(resolution = 10.0), FixedScale(resolution = 100.0)] ticker = ScaleSystem(default_scale=None, *scales) self.check_ticks(ticker.ticks(5, 35, 3), (10.0, 20.0, 30.0)) self.check_ticks(ticker.ticks(5, 35, 20), frange(5.0, 35.0, 1.0)) self.check_ticks(ticker.ticks(5, 614, 10), (100, 200, 300, 400, 500, 600))
def test_yearly_scales(self): ticker = ScaleSystem(TimeScale(month_of_year=1), default_scale=None) ticks = ticker.ticks(DTS(2000, 1, 1), DTS(2007, 1, 1), 10) desired = list( starmap(DTS, ((2000, 1, 1), (2001, 1, 1), (2002, 1, 1), (2003, 1, 1), (2004, 1, 1), (2005, 1, 1), (2006, 1, 1), (2007, 1, 1)))) self.check_ticks(ticks, desired)
def test_width_based_default_scale(self): scale = ScaleSystem() test_intervals = ((1, 100, 80), (1, 100, 40), (1, 100, 20),) print for start, end, width in test_intervals: labels = scale.labels(start, end, char_width=width) print "(%d,%d)" % (start,end), " avail:", width, print " used:", sum([len(x[1]) for x in labels]) return
def test_labels(self): fmt = TimeFormatter() scale = ScaleSystem(*HMSScales) test_intervals = ([(2005,3,15,10,30), (2005,3,15,10,50), 150], ) print for start, end, width in test_intervals: labels = scale.labels(DTS(*start), DTS(*end), char_width=width) print start, end, " avail:", width, print " used:", sum([len(x[1]) for x in labels]), print labels return
def test_scale_system(self): scale = ScaleSystem(FixedScale(resolution = 1.0), FixedScale(resolution = 2.5), FixedScale(resolution = 5.0), FixedScale(resolution = 10.0), FixedScale(resolution = 20.0), FixedScale(resolution = 100.0)) test_intervals = ((1,100,200), (1, 100, 80), (1, 100, 40), (1, 100, 20), (1, 100, 5), (1, 10, 100), (1, 10, 50), (1, 10, 20),) print for start, end, width in test_intervals: labels = scale.labels(start, end, char_width=width) print "(%d,%d)" % (start,end), " avail:", width, print " used:", sum([len(x[1]) for x in labels]), print list(zip(*labels))[1] return
def test_yearly_scales(self): ticker = ScaleSystem(TimeScale(month_of_year=1), default_scale=None) ticks = ticker.ticks(DTS(2000,1,1), DTS(2007,1,1), 10) desired = list(starmap(DTS, ((2000,1,1), (2001,1,1), (2002,1,1), (2003,1,1), (2004,1,1), (2005,1,1), (2006,1,1), (2007,1,1)))) self.check_ticks(ticks, desired)
def test_defaults(self): ticker = ScaleSystem() ticks = ticker.ticks(5, 30, 10) self.check_ticks(ticks, frange(5.0, 30.0, 2.5))