MCPcopy Create free account
hub / github.com/akeranen/the-one / testCostValues

Method testCostValues

test/MaxPropRouterTest.java:37–101  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35 }
36
37 public void testCostValues() {
38 /* create messages so we can ask for msg costs */
39
40 Message m1 = new Message(h1,h2, msgId2, 10);
41 h1.createNewMessage(m1);
42 Message m2 = new Message(h1,h3, msgId3, 10);
43 h1.createNewMessage(m2);
44 Message m3 = new Message(h1,h4, msgId4, 10);
45 h1.createNewMessage(m3);
46
47 Message m4 = new Message(h2,h1, msgId5, 10);
48 h2.createNewMessage(m4);
49 checkCreates(4);
50
51 /* there should be no routes before connects */
52 assertEquals(INVALID_COST, r1.getCost(h1, h2));
53 assertEquals(INVALID_COST, r2.getCost(h2, h1));
54
55 h1.connect(h2);
56 assertEquals(0.0, r1.getCost(h1, h2)); // zero cost route to only known
57 assertEquals(0.0, r2.getCost(h2, h1));
58
59 disconnect(h1); // disconnect should not affect the costs
60 assertEquals(0.0, r1.getCost(h1, h2));
61 assertEquals(0.0, r2.getCost(h2, h1));
62
63 h1.connect(h2); // costs should stay the same (only 1 known host)
64 assertEquals(0.0, r1.getCost(h1, h2));
65 assertEquals(0.0, r2.getCost(h2, h1));
66
67 disconnect(h1);
68 h1.connect(h3);
69 assertEquals(0.5, r1.getCost(h1, h2));
70 assertEquals(0.5, r1.getCost(h1, h3));
71 assertEquals(0.0, r2.getCost(h2, h1)); // h2's costs should not change
72
73 disconnect(h1);
74 h1.connect(h3);
75 /* h1's prob of meeting h2 is 0.5/2 -> cost 1-0.5/2 */
76 assertEquals( 1 - 0.5/2 , r1.getCost(h1, h2));
77 assertEquals( 1 - (1+0.5)/2 , r1.getCost(h1, h3));
78
79 disconnect(h1);
80 h1.connect(h3);
81 assertEquals( 1 - (0.5/2)/2 , r1.getCost(h1, h2));
82 assertEquals( 1 - (1+(1+0.5)/2)/2 , r1.getCost(h1, h3));
83 /* probabilities sum to 1.0 */
84 assertEquals(1.0, (1-r1.getCost(h1, h2)) + (1-r1.getCost(h1, h3)));
85
86 h1.connect(h4);
87 assertEquals( 1 - ((0.5/2)/2)/2 , r1.getCost(h1, h2));
88 assertEquals( 1 - ((1+(1+0.5)/2)/2)/2 , r1.getCost(h1, h3));
89 assertEquals( 1 - 0.5 , r1.getCost(h1, h4));
90 assertEquals(1.0, (1-r1.getCost(h1, h2)) + (1-r1.getCost(h1, h3)) +
91 (1-r1.getCost(h1, h4)));
92
93 disconnect(h1);
94 h1.connect(h2); // reconnect to h2

Callers

nothing calls this directly

Calls 5

checkCreatesMethod · 0.80
createNewMessageMethod · 0.45
getCostMethod · 0.45
connectMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected