def testAdd(self): addend1 = Number(5) addend2 = Number(2) sum = Number(7) self.assertTrue(self.math.Equals(self.math.Add(addend1, addend2), sum), 'incorrect result')
def testDivide(self): dividend = Number(8) divisor = Number(4) quotient = Number(8 / 4) self.assertTrue( self.math.Equals(self.math.Divide(dividend, divisor), quotient), 'incorrect result')
def testMultiply(self): multiplicand = Number(2) multiplier = Number(4) product = Number(2 * 4) self.assertTrue( self.math.Equals(self.math.Multiply(multiplicand, multiplier), product), 'incorrect result')
def testSubtract(self): minuend = Number(5) subtrahend = Number(2) difference = Number(3) self.assertTrue( self.math.Equals(self.math.Subtract(minuend, subtrahend), difference), 'incorrect result')
def testLessThan(self): first = Number(1) second = Number(2) lessThanResult = 1 < 2 greaterThanResult = 1 > 2 self.assertTrue( self.math.LessThan(first, second) == lessThanResult, 'incorrect result') self.assertTrue( self.math.GreaterThan(first, second) == greaterThanResult, 'incorrect result')
def generateShuffledList(self, length): items = list(range(1, 1 + length + 1)) random.shuffle(items) numbers = [] for item in items: numbers.append(Number(item)) return numbers
def generateSortedList(self, length): items = list(range(1, 1 + length + 1)) numbers = [] for item in items: numbers.append(Number(item)) return numbers
#!/usr/bin/python from maths import Arithmetic, Number from search import * print("Do some arithmetic") print("2 + 3 = %d" % Arithmetic().Add(Number(2), Number(3)).value) print("8 - 3 = %d" % Arithmetic().Subtract(Number(8), Number(3)).value) print("4 * 5 = %d" % Arithmetic().Multiply(Number(4), Number(5)).value) print("16 / 4 = %d" % Arithmetic().Divide(Number(16), Number(4)).value) print("Equality Tests") print("2 == 2 is %s" % Arithmetic().Equals(Number(2), Number(2))) print("1 == 2 is %s" % Arithmetic().Equals(Number(1), Number(2))) def print_graph_details(algorithm): print("Vertices: ") for n in algorithm.nodes: v = algorithm.nodes[n] print("{}: {} ({},{})".format(v.id, v.name, v.position.lat, v.position.lon)) print("Edges: ") for a in algorithm.graph: e = algorithm.graph[a] print( "[{}] {} ".format(algorithm.nodes[a].id, algorithm.nodes[a].name), e) import time