from mpTcptraceData import * import numpy as np # to get a REPL: #import code #code.interact(local=locals()) # A checker runs tests, and a test is made of multiple validations # For a validation, the value to compare to is the target value from the yaml # The validation takes place in the validate method, which takes # as argument a value from which to extract the value to compare or the value itself class Validation: def __init__(self, yml): if "target" in yml: self.compared=yml["target"] else: self.compared=None def name(self): return self.__class__.__name__ def validate(self,value): raise Exception("Method not implemented") def setup(self): raise Exception("Method not implemented") # checks a value passed is greater or equal (generic) class MinValueValidation(Validation): def validate(self, value): self.value = value return self.compared<=value # checks a value passed is greater or equal (generic) class MaxValueValidation(Validation): def validate(self, value): self.value = value return self.compared>=value # checks a value passed is greater or equal (generic) class ExactValueValidation(Validation): def validate(self, value): self.value = value return self.compared==value # the method get_tested_value of the tester returns the value passed to validate. # the CsvTester returns an array of values class MinDifferenceValidation(Validation): def validate(self, value): v = value.flatten() if len(v)>2: raise Exception("MinDifferenceValidation requires 2 values maximum, not "+ str(len(v))) self.value = float(v[1])-float(v[0]) return self.compared<=self.value class MinRowsValidation(Validation): def validate(self, value): self.value = len(value) return self.compared<=self.value class MaxRowsValidation(Validation): def validate(self, value): self.value = len(value) return self.compared>=self.value class ExactRowsValidation(Validation): def validate(self, value): self.value = len(value) return self.compared==self.value class MaxRatioValidation(Validation): def validate(self, value): v = value.flatten() if len(v)>2: raise Exception("MinDifferenceValidation requires 2 values maximum, not "+ str(len(v))) self.value = float(v[1])/(float(v[0])+float(v[1])) return self.compared>=self.value # validates all values passed have increasing values # it is the Tester's get_tested_value method that does the work # to extract the values list from the trace. class IncreasingValuesValidation(Validation): def validate(self, values): previous = 0 for i,v in enumerate(values.flatten()): #print i, "{:10.6f}".format(previous), "{:10.6f}".format(v) if v