test generator fix
This commit is contained in:
		
							parent
							
								
									1624a9a06f
								
							
						
					
					
						commit
						eccff7691f
					
				| 
						 | 
					@ -5,15 +5,14 @@ from ipaddress import IPv6Network
 | 
				
			||||||
def parse_rule(rule):
 | 
					def parse_rule(rule):
 | 
				
			||||||
    parts = rule.split()
 | 
					    parts = rule.split()
 | 
				
			||||||
    prefix, next_hop = parts
 | 
					    prefix, next_hop = parts
 | 
				
			||||||
    return prefix, int(next_hop)
 | 
					    return IPv6Network(prefix), int(next_hop)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def generate_random_test_cases(rules, n):
 | 
					def generate_random_test_cases(rules, n):
 | 
				
			||||||
    with open('../data/test-data', 'w') as f:
 | 
					    with open('../data/test-data', 'w') as f:
 | 
				
			||||||
        for rule in rules:
 | 
					        for rule in rules:
 | 
				
			||||||
            rule_prefix = rule[0]
 | 
					            rule_network = rule[0]
 | 
				
			||||||
            rule_next_hop = rule[1]
 | 
					            rule_next_hop = rule[1]
 | 
				
			||||||
            rule_network = IPv6Network(rule_prefix)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for _ in range(n):
 | 
					            for _ in range(n):
 | 
				
			||||||
                next_hop = rule_next_hop
 | 
					                next_hop = rule_next_hop
 | 
				
			||||||
| 
						 | 
					@ -22,15 +21,16 @@ def generate_random_test_cases(rules, n):
 | 
				
			||||||
                for oth_rule in rules:
 | 
					                for oth_rule in rules:
 | 
				
			||||||
                    if oth_rule == rule:
 | 
					                    if oth_rule == rule:
 | 
				
			||||||
                        continue
 | 
					                        continue
 | 
				
			||||||
                    oth_prefix = oth_rule[0]
 | 
					                    oth_network = oth_rule[0]
 | 
				
			||||||
                    oth_next_hop = oth_rule[1]
 | 
					                    oth_next_hop = oth_rule[1]
 | 
				
			||||||
                    if address in IPv6Network(oth_prefix) and rule_prefix < oth_prefix:
 | 
					                    if address in oth_network and oth_network.subnet_of( rule_network ):
 | 
				
			||||||
 | 
					                        print(f"address {address} is closer to {oth_network} {rule_next_hop} than {rule_network} {oth_next_hop}")
 | 
				
			||||||
                        next_hop = oth_next_hop
 | 
					                        next_hop = oth_next_hop
 | 
				
			||||||
                f.write(f"{address} {next_hop}\n")
 | 
					                f.write(f"{address} {next_hop}\n")
 | 
				
			||||||
                # print(f"Generated test case: {address} {next_hop}")
 | 
					                print(f"Generated test case: {address} {next_hop}")
 | 
				
			||||||
            print("tests for rule ", rule_prefix, " with next hop ", rule_next_hop, " generated")
 | 
					            print("tests for rule ", rule_network, " with next hop ", rule_next_hop, " generated")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():     #1111:2222:3333:4444:5555:6666:7777:88 120
 | 
					def main():
 | 
				
			||||||
    rules = []
 | 
					    rules = []
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    with open('../data/routing-data', 'r') as f:
 | 
					    with open('../data/routing-data', 'r') as f:
 | 
				
			||||||
| 
						 | 
					@ -39,7 +39,7 @@ def main():     #1111:2222:3333:4444:5555:6666:7777:88 120
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    parsed_rules = [parse_rule(rule) for rule in rules]
 | 
					    parsed_rules = [parse_rule(rule) for rule in rules]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    num_tests = 10  # Change this to desired number of tests
 | 
					    num_tests = 10
 | 
				
			||||||
    generate_random_test_cases(parsed_rules, num_tests)
 | 
					    generate_random_test_cases(parsed_rules, num_tests)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
           
 | 
					           
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue