def webster_has_def(): # define rules to use greater_rule = Rule(RuleType.GREATER, 3) less_rule = Rule(RuleType.LESS, 10) and_rule = Rule(RuleType.AND, [greater_rule, less_rule]) contain_rule = Rule(RuleType.CONTAIN, 'h') xor_rule = Rule(RuleType.XOR, [contain_rule, Rule(RuleType.CONTAIN, 'o')]) # define properties to use name_prop = Property("Name", xor_rule) valu_prop = Property("Value", and_rule) # define a definition for testing definition = Definition("TestyDef", [name_prop, valu_prop]) # define a thing attrs1 = {"Name": "Hello", "Value": 5} attrs2 = {"Name": "hello", "Value": 1} thing1 = Thing("Thing 1", attributes=attrs1, definition="TestyDef") thing2 = Thing("Thing 2", attributes=attrs2) thing3 = Thing("Thing Red", attributes=attrs2, definition="TestyDef") thing4 = Thing("Thing Blue", attributes=attrs1) brain = [thing1, thing2, thing3, thing4] # runs test webster = Webster(brain=brain, dictionary=[definition]) result1 = webster.has_definition("Thing 1", "TestyDef") result2 = webster.has_definition("Thing 2", "TestyDef") result3 = webster.has_definition("Thing Red", "TestyDef") result4 = webster.has_definition("Thing Blue", "TestyDef") test("Webster Has Definition 1", result1, True) test("Webster Has Definition 2", result2, False) test("Webster Has Definition 3", result3, True) test("Webster Has Definition 4", result4, True)
def webster_eq(): # define rules to use greater_rule = Rule(RuleType.GREATER, 3) less_rule = Rule(RuleType.LESS, 10) and_rule = Rule(RuleType.AND, [greater_rule, less_rule]) contain_rule = Rule(RuleType.CONTAIN, 'h') xor_rule = Rule(RuleType.XOR, [contain_rule, Rule(RuleType.CONTAIN, 'o')]) # define properties to use name_prop = Property("Name", xor_rule) valu_prop = Property("Value", and_rule) # define a definition for testing definition = Definition("TestyDef", [name_prop, valu_prop]) # define a thing attrs = {"Name": "Hello", "Value": 3} thing = Thing("TestyThingy", attributes=attrs, definition="TestyDef") # defines Webster webster1 = Webster(brain=[thing], dictionary=[definition]) webster2 = Webster(brain=[thing], dictionary=[definition]) webster3 = Webster(dictionary=[definition]) webster4 = Webster(brain=[thing]) test("Webster Equality", webster1 == webster2, True) test("Webster Inequality 1", webster1 == webster3, False) test("Webster Inequality 2", webster1 == webster4, False)
def init_webster(): # define rules to use greater_rule = Rule(RuleType.GREATER, 3) less_rule = Rule(RuleType.LESS, 10) and_rule = Rule(RuleType.AND, [greater_rule, less_rule]) contain_rule = Rule(RuleType.CONTAIN, 'h') xor_rule = Rule(RuleType.XOR, [contain_rule, Rule(RuleType.CONTAIN, 'o')]) # define properties to use name_prop = Property("Name", xor_rule) valu_prop = Property("Value", and_rule) # define a definition for testing definition = Definition("TestyDef", [name_prop, valu_prop]) # define a thing attrs = {"Name": "Hello", "Value": 3} thing = Thing("TestyThingy", attributes=attrs, definition="TestyDef") # defines Webster webster = Webster(brain=[thing], dictionary=[definition]) # tests for the correct values dict_test = webster.dictionary["TestyDef"] test("Webster Construction Dictionary", dict_test, definition) test("Webster Construction Brain", webster.brain["TestyThingy"], thing)
def definition_eq(): # define rules to use greater_rule = Rule(RuleType.GREATER, 3) less_rule = Rule(RuleType.LESS, 10) and_rule = Rule(RuleType.AND, [greater_rule, less_rule]) contain_rule = Rule(RuleType.CONTAIN, 'h') xor_rule = Rule(RuleType.XOR, [contain_rule, Rule(RuleType.CONTAIN, 'o')]) # define properties to use name_prop = Property("Name", xor_rule) valu_prop = Property("Value", and_rule) # run the test def1 = Definition("TestyDef", [name_prop, valu_prop]) def2 = Definition("TestyDef", [name_prop, valu_prop]) def3 = Definition("TestDef", [name_prop, valu_prop]) def4 = Definition("TestyDef", [name_prop]) test("Definition Equality", def1 == def2, True) test("Definition Inequality 1", def1 == def3, False) test("Definition Inequality 2", def1 == def4, False)
def definition_match(): # define rules to use greater_rule = Rule(RuleType.GREATER, 3) less_rule = Rule(RuleType.LESS, 10) and_rule = Rule(RuleType.AND, [greater_rule, less_rule]) contain_rule = Rule(RuleType.CONTAIN, 'h') xor_rule = Rule(RuleType.XOR, [contain_rule, Rule(RuleType.CONTAIN, 'o')]) # define properties to use name_prop = Property("Name", xor_rule) valu_prop = Property("Value", and_rule) # define a definition for testing definition = Definition("TestyDef", [name_prop, valu_prop]) # define a thing for testing thing = Thing("TestyThingy", attributes={"Name": "Hello", "Value": 4}) test("Definition Match 1", definition.match(thing), True) thing = Thing("TestyThingy", attributes={"Name": "hello", "Value": 4}) test("Definition Match 2", definition.match(thing), False) thing = Thing("TestyThingy", attributes={"Name": "Hello", "Value": 3}) test("Definition Match 3", definition.match(thing), False)
def webster_add_definition(): # define rules to use greater_rule = Rule(RuleType.GREATER, 3) less_rule = Rule(RuleType.LESS, 10) and_rule = Rule(RuleType.AND, [greater_rule, less_rule]) contain_rule = Rule(RuleType.CONTAIN, 'h') xor_rule = Rule(RuleType.XOR, [contain_rule, Rule(RuleType.CONTAIN, 'o')]) # define properties to use name_prop = Property("Name", xor_rule) valu_prop = Property("Value", and_rule) # runs test definition = Definition("TestyDef", [name_prop, valu_prop]) webster = Webster() webster.add_definition("TestyDef", [name_prop, valu_prop]) result = webster.get_definition("TestyDef") test("Webster Add Definition", result, definition)
def init_definition(): # define rules to use greater_rule = Rule(RuleType.GREATER, 3) less_rule = Rule(RuleType.LESS, 10) and_rule = Rule(RuleType.AND, [greater_rule, less_rule]) contain_rule = Rule(RuleType.CONTAIN, 'h') xor_rule = Rule(RuleType.XOR, [contain_rule, Rule(RuleType.CONTAIN, 'o')]) # define properties to use name_prop = Property("Name", xor_rule) valu_prop = Property("Value", and_rule) # define a definition for testing definition = Definition("TestyDef", [name_prop, valu_prop]) # the expected value of definition.prop exp_prop = {"Name": name_prop, "Value": valu_prop} test("Definition Construction Name", definition.name, "TestyDef") test("Definition Construction Properties", definition.props, exp_prop)
def webster_get_definition(): # define rules to use greater_rule = Rule(RuleType.GREATER, 3) less_rule = Rule(RuleType.LESS, 10) and_rule = Rule(RuleType.AND, [greater_rule, less_rule]) contain_rule = Rule(RuleType.CONTAIN, 'h') xor_rule = Rule(RuleType.XOR, [contain_rule, Rule(RuleType.CONTAIN, 'o')]) # define properties to use name_prop = Property("Name", xor_rule) valu_prop = Property("Value", and_rule) # define a definition for testing definition = Definition("TestyDef", [name_prop, valu_prop]) # defines Webster webster = Webster(dictionary=[definition]) # tests to get the definition test_result = webster.get_definition("TestyDef") test("Webster Get Definition", test_result, definition)