def test_02(self): """TestXGrid.test_02(): genEvents() with 2/5/10/25, xInc=False.""" #print() myXs = XGrid.XGrid(200) v = 0 eventS = [] for e in myXs._genEvents( xFrom=0, xInc=True, eMap={ 2: 'two', 5: 'five', 10: 'ten', 25: 'twenty five', }, ): #print(e) eventS.append(e) v += 1 if v > 25: break #print() #pprint.pprint(eventS) self.assertEqual([(0, 'twenty five'), (2, 'two'), (4, 'two'), (5, 'five'), (6, 'two'), (8, 'two'), (10, 'ten'), (12, 'two'), (14, 'two'), (15, 'five'), (16, 'two'), (18, 'two'), (20, 'ten'), (22, 'two'), (24, 'two'), (25, 'twenty five'), (26, 'two'), (28, 'two'), (30, 'ten'), (32, 'two'), (34, 'two'), (35, 'five'), (36, 'two'), (38, 'two'), (40, 'ten'), (42, 'two')], eventS)
def test_03(self): """TestXGrid.test_03(): genEvents() with 2/5/10/25, xInc=False.""" #print() myXs = XGrid.XGrid(200) v = 0 eventS = [] for e in myXs._genEvents( xFrom=0, xInc=False, eMap={ 2: 'two', 5: 'five', 10: 'ten', 25: 'twenty five', }, ): #print(e) eventS.append(e) v += 1 if v > 25: break #print() #pprint.pprint(eventS) self.assertEqual([(0, 'twenty five'), (-2, 'two'), (-4, 'two'), (-5, 'five'), (-6, 'two'), (-8, 'two'), (-10, 'ten'), (-12, 'two'), (-14, 'two'), (-15, 'five'), (-16, 'two'), (-18, 'two'), (-20, 'ten'), (-22, 'two'), (-24, 'two'), (-25, 'twenty five'), (-26, 'two'), (-28, 'two'), (-30, 'ten'), (-32, 'two'), (-34, 'two'), (-35, 'five'), (-36, 'two'), (-38, 'two'), (-40, 'ten'), (-42, 'two')], eventS)
def test_21(self): """TestXGridRange.test_21(): genXAxisTextRange() with 'non-optical' units b'.1IN'.""" myXs = XGrid.XGrid(200) myVals = [ v for v in myXs.genXAxisTextRange( EngVal.EngVal(4001.0, b'FEET').newEngValInUnits(b'.1IN'), EngVal.EngVal(3499.0, b'FEET').newEngValInUnits(b'.1IN'), ) ] self.assertEqual(6, len(myVals)) # print() # pprint.pprint(myVals) self.assertEqual( # [ # (Coord.Dim(value=-0.06000000000000001, units='in'), 4000), # (Coord.Dim(value=-6.06, units='in'), 3900), # (Coord.Dim(value=-12.06, units='in'), 3800), # (Coord.Dim(value=-18.06, units='in'), 3700), # (Coord.Dim(value=-24.06, units='in'), 3600), # (Coord.Dim(value=-30.060000000000006, units='in'), 3500), # ], [ (Coord.Dim(value=-0.060000000000027295, units='in'), 4000), (Coord.Dim(value=-6.060000000000027, units='in'), 3900), (Coord.Dim(value=-12.060000000000029, units='in'), 3800), (Coord.Dim(value=-18.060000000000027, units='in'), 3700), (Coord.Dim(value=-24.060000000000027, units='in'), 3600), (Coord.Dim(value=-30.06000000000003, units='in'), 3500), ], myVals, )
def test_01(self): """TestXGridRange.test_01(): genXAxisRange().""" myXs = XGrid.XGrid(200) myVals = [ v for v in myXs.genXAxisRange(EngVal.EngVal(4001.0, b'FEET'), EngVal.EngVal(3987.0, b'FEET')) ] #print() #pprint.pprint(myVals) self.assertEqual( [ (Coord.Dim(value=-0.06000000000000001, units='in'), Stroke.Stroke( width=1.0, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.18000000000000005, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.3, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.42, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.54, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.66, units='in'), Stroke.Stroke( width=0.5, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.78, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), ], myVals, )
def test_20(self): """TestXGridRange.test_20(): genXAxisRange() with 'non-optical' units b'.1IN'.""" myXs = XGrid.XGrid(200) myVals = [ v for v in myXs.genXAxisRange( EngVal.EngVal(4001.0, b'FEET').newEngValInUnits(b'.1IN'), EngVal.EngVal(3987.0, b'FEET').newEngValInUnits(b'.1IN'), ) ] self.assertEqual(7, len(myVals)) # print() # pprint.pprint(myVals) self.assertEqual( # [ # (Coord.Dim(value=-0.06000000000000001, units='in'), # Stroke.Stroke(width=1.0, colour='black', coding=None, opacity=1.0)), # (Coord.Dim(value=-0.18000000000000005, units='in'), # Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), # (Coord.Dim(value=-0.3, units='in'), # Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), # (Coord.Dim(value=-0.42, units='in'), # Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), # (Coord.Dim(value=-0.54, units='in'), # Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), # (Coord.Dim(value=-0.66, units='in'), # Stroke.Stroke(width=0.5, colour='black', coding=None, opacity=1.0)), # (Coord.Dim(value=-0.78, units='in'), # Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), # ], [ (Coord.Dim(value=-0.060000000000027295, units='in'), Stroke.Stroke( width=1.0, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.18000000000002728, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.3000000000000273, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.4200000000000273, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.5400000000000273, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.6600000000000272, units='in'), Stroke.Stroke( width=0.5, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.7800000000000273, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), ], myVals, )
def test_01(self): """TestXGrid.test_01(): genXAxisText() 5 values from 4307.5 upwards.""" myXs = XGrid.XGrid(200) #print() v = 0 eventS = [] for e in myXs._genXAxisText(xFrom=4307.5, xInc=False, units=b'FEET'): eventS.append(e) v += 1 if v > 4: break #pprint.pprint(eventS) self.assertEqual([4300, 4200, 4100, 4000, 3900,], eventS)
def test_04(self): """TestXGrid.test_04(): ctor uses default _setInterval(), test _getInterval().""" #print() myXs = XGrid.XGrid(200) #print(myXs._getInterval(b'FEET')) self.assertEqual( { 2 : Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0), 10 : Stroke.Stroke(width=0.5, colour='black', coding=None, opacity=1.0), 50 : Stroke.Stroke(width=0.75, colour='black', coding=None, opacity=1.0), 100 : Stroke.Stroke(width=1.0, colour='black', coding=None, opacity=1.0), }, myXs._getInterval(b'FEET'), )
def test_10(self): """TestXGrid.test_10(): genXAxisStroke() plotting UP with FEET and 1/200.""" #print() myXs = XGrid.XGrid(200) v = 0 eventS = [] for e in myXs._genXAxisStroke(xFrom=4307.5, xInc=False, units=b'FEET'): #print(e) eventS.append(e) v += 1 if v > 30: break #pprint.pprint(eventS) self.assertEqual( [ (4306, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4304, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4302, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4300, Stroke.Stroke(width=1.0, colour='black', coding=None, opacity=1.0)), (4298, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4296, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4294, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4292, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4290, Stroke.Stroke(width=0.5, colour='black', coding=None, opacity=1.0)), (4288, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4286, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4284, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4282, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4280, Stroke.Stroke(width=0.5, colour='black', coding=None, opacity=1.0)), (4278, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4276, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4274, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4272, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4270, Stroke.Stroke(width=0.5, colour='black', coding=None, opacity=1.0)), (4268, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4266, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4264, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4262, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4260, Stroke.Stroke(width=0.5, colour='black', coding=None, opacity=1.0)), (4258, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4256, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4254, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4252, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4250, Stroke.Stroke(width=0.75, colour='black', coding=None, opacity=1.0)), (4248, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), (4246, Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)), ], eventS )
def test_02(self): """TestXGrid.test_02(): genXPosText() 5 values from 4307.5 upwards.""" myXs = XGrid.XGrid(200) #print() v = 0 eventS = [] for e in myXs._genXPosText(xFrom=4307.5, xInc=False, units=b'FEET'): eventS.append(e) v += 1 if v > 4: break #pprint.pprint(eventS) self.assertEqual([ (Coord.Dim(value=-0.45, units='in'), 4300), (Coord.Dim(value=-6.45, units='in'), 4200), (Coord.Dim(value=-12.45, units='in'), 4100), (Coord.Dim(value=-18.45, units='in'), 4000), (Coord.Dim(value=-24.45, units='in'), 3900), ], eventS)
def test_10(self): """TestXGridRange.test_10(): genXAxisTextRange().""" myXs = XGrid.XGrid(200) myVals = [ v for v in myXs.genXAxisTextRange(EngVal.EngVal(4001.0, b'FEET'), EngVal.EngVal(3499.0, b'FEET')) ] #print() #pprint.pprint(myVals) self.assertEqual( [ (Coord.Dim(value=-0.06000000000000001, units='in'), 4000), (Coord.Dim(value=-6.06, units='in'), 3900), (Coord.Dim(value=-12.06, units='in'), 3800), (Coord.Dim(value=-18.06, units='in'), 3700), (Coord.Dim(value=-24.06, units='in'), 3600), (Coord.Dim(value=-30.060000000000006, units='in'), 3500), ], myVals, )
def test_01(self): """TestXGrid.test_01(): Constructor.""" myXs = XGrid.XGrid(200)
def test_11(self): """TestXGrid.test_11(): genXPosStroke() plotting UP with FEET and 1/200.""" #print() myXs = XGrid.XGrid(200) v = 0 eventS = [] for e in myXs.genXPosStroke(xFrom=4307.5, xInc=False, units=b'FEET'): #print(e) eventS.append(e) v += 1 if v > 30: break #pprint.pprint(eventS) self.assertEqual([ (Coord.Dim(value=-0.09000000000000002, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.21, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.33, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.45, units='in'), Stroke.Stroke(width=1.0, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.57, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.6900000000000002, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.81, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-0.93, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-1.05, units='in'), Stroke.Stroke(width=0.5, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-1.17, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-1.29, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-1.4100000000000004, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-1.53, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-1.65, units='in'), Stroke.Stroke(width=0.5, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-1.77, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-1.8900000000000003, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-2.0100000000000002, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-2.1300000000000003, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-2.25, units='in'), Stroke.Stroke(width=0.5, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-2.37, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-2.49, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-2.61, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-2.7300000000000004, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-2.8500000000000005, units='in'), Stroke.Stroke(width=0.5, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-2.97, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-3.09, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-3.21, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-3.33, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-3.45, units='in'), Stroke.Stroke( width=0.75, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-3.57, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), (Coord.Dim(value=-3.69, units='in'), Stroke.Stroke( width=0.25, colour='black', coding=None, opacity=1.0)), ], eventS)
def test_09(self): """TestXGrid.test_09(): _setIntervalText() fails.""" #print() myXs = XGrid.XGrid(200) self.assertRaises(XGrid.ExceptionPlotXGrid, myXs._setIntervalText, 'in', 200.0, {})
def test_08(self): """TestXGrid.test_08(): ctor uses default _setInterval(), test _getInterval() defaults.""" #print() myXs = XGrid.XGrid(200) self.assertEqual(XGrid.XGrid.DEFAULT_INTERVAL_TEXT, myXs._getIntervalText(b' '))
def test_07(self): """TestXGrid.test_07(): ctor uses default _setInterval(), test _getIntervalText().""" #print() myXs = XGrid.XGrid(200) #print(myXs._getInterval(b'FEET')) self.assertEqual(100, myXs._getIntervalText(b'FEET'))
def test_00(self): """TestPlotTrack.test_00(): Construct a lin/log/log track with FEET 1/200 and plot it in SVG.""" myCnv = Plot.Canvas(Coord.Dim(8.5, 'in'), Coord.Dim(12, 'in'), PlotConstants.MarginQtrInch) myViewPort = Coord.Box( width=myCnv.width, depth=myCnv.depth, ) myTopLeft = Coord.Pt(Coord.Dim(0.25, 'in'), Coord.Dim(0.25, 'in')) myF = io.StringIO() myTracks = [ Track.Track(leftPos=Coord.Dim(0.0, 'in'), rightPos=Coord.Dim(2.4, 'in'), gridGn=Track.genLinear10), Track.Track( leftPos=Coord.Dim(2.4, 'in'), rightPos=Coord.Dim(3.2, 'in'), gridGn=None, plotXAxis=True, ), Track.Track(leftPos=Coord.Dim(3.2, 'in'), rightPos=Coord.Dim(5.6, 'in'), gridGn=Track.genLog10Decade2Start2), Track.Track(leftPos=Coord.Dim(5.6, 'in'), rightPos=Coord.Dim(8, 'in'), gridGn=Track.genLog10Decade2Start2), ] with SVGWriter.SVGWriter(myF, myViewPort) as xS: # Do tracks first for t in myTracks: #xS.comment(str(t)) if t.hasGrid: t.plotSVG( myTopLeft, myCnv.depth - myCnv.margins.top - myCnv.margins.bottom, xS, ) # Now XGrid # We are plotting up so xPosStart is at bottom myXposStart = myCnv.depth - myCnv.margins.bottom myXposStop = myCnv.margins.top myXg = XGrid.XGrid(200) # Plot depth lines for pos, stroke in myXg.genXPosStroke(xFrom=4307.5, xInc=False, units=b'FEET'): myXpos = myXposStart + pos if myXpos < myXposStop: break for t in myTracks: if t.hasGrid: with SVGWriter.SVGLine( xS, Coord.Pt(t.left + myCnv.margins.left, myXpos), Coord.Pt(t.right + myCnv.margins.left, myXpos), attrs=Stroke.retSVGAttrsFromStroke(stroke)): pass # Plot depth text textAttrs = { 'text-anchor': 'end', 'dominant-baseline': 'middle', } for pos, val in myXg.genXPosText(xFrom=4307.5, xInc=False, units=b'FEET'): myXpos = myXposStart + pos if myXpos < myXposStop: break for t in myTracks: if t.plotXAxis: myPt = Coord.Pt( t.right + myCnv.margins.left - Coord.Dim(0.05, 'in'), myXpos) with SVGWriter.SVGText(xS, myPt, 'Courier', 16, textAttrs): xS.characters(str(val)) print() print(myF.getvalue())