fixed closeness calculation
This commit is contained in:
		
							parent
							
								
									57ec04eff5
								
							
						
					
					
						commit
						4a831a4a4d
					
				
					 3 changed files with 46 additions and 20 deletions
				
			
		|  | @ -15,13 +15,6 @@ from streamfill import identify_neighbors, extract_ed25519_from_onion_address | |||
| 
 | ||||
| class TestStreamfillNeighbors(unittest.TestCase): | ||||
|     def test_neighbor_closeness_consistent(self): | ||||
|         onions = [] | ||||
|         # p = subprocess.Popen(["scripts/generate-onions.py", '5'], | ||||
|         #                      stdout=subprocess.PIPE, | ||||
|         #                      stderr=subprocess.PIPE) | ||||
|         # for line in iter(p.stdout.readline, b''): | ||||
|         #     line = line.decode() | ||||
|         #     onions.append(line.strip()) | ||||
|         main = '7uifxsgidchopmdwmtip6x4ydra6cpf2ov4ghj2lzx5uydyssduh5qid.onion' | ||||
|         others = ['bxxajpimlonmbxb5jzjre3go3dvfobqyayqwpksd6zpjz4s4mknstwyd.onion', '2zofaifd6s3flwbv5wl4vtgnesbprc4f2ptljl4a47dfkvrbmw3e5iqd.onion', '6umslj7jtzu27n4jgf3byn55ztz5mkoqocx32zwjya6rbnxqjpyysyyd.onion'] | ||||
|         main_num = int.from_bytes(extract_ed25519_from_onion_address(main), 'big') | ||||
|  | @ -31,12 +24,13 @@ class TestStreamfillNeighbors(unittest.TestCase): | |||
|         my_result = [] | ||||
|         for i in others: | ||||
|             my_result.append((i, abs(main_num - int.from_bytes(extract_ed25519_from_onion_address(i), 'big')))) | ||||
|         my_result.sort() | ||||
|         my_result.sort(key=lambda p: p[1]) | ||||
| 
 | ||||
|         final = [] | ||||
|         for i in my_result: | ||||
|             final.append(i[0]) | ||||
|         self.assertTrue(len(test_data) == 3) | ||||
|         self.assertListEqual(test_data, final) | ||||
|         self.assertListEqual(final, test_data) | ||||
| 
 | ||||
| 
 | ||||
|     def test_neighbor_closeness_random(self): | ||||
|         onions = [] | ||||
|  | @ -55,12 +49,12 @@ class TestStreamfillNeighbors(unittest.TestCase): | |||
|         my_result = [] | ||||
|         for i in onions: | ||||
|             my_result.append((i, abs(main_num - int.from_bytes(extract_ed25519_from_onion_address(i), 'big')))) | ||||
|         my_result.sort() | ||||
|         my_result.sort(key=lambda p: p[1]) | ||||
| 
 | ||||
|         final = [] | ||||
|         for i in my_result: | ||||
|             final.append(i[0]) | ||||
|         self.assertTrue(len(test_data) == 100) | ||||
|         self.assertListEqual(test_data, final) | ||||
|         self.assertListEqual(final, test_data) | ||||
| 
 | ||||
| 
 | ||||
| unittest.main() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue