diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-10-14 05:50:27 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-10-14 05:50:27 +0200 |
commit | fc9fdd313bc08a4f290780dfa1cf9133eddf3bf3 (patch) | |
tree | 80ca12d4f59776fe825a5a596053f398ada2b7c2 | |
parent | e333dd01839038942ae724305316f8df1196103d (diff) | |
download | libbrandt-fc9fdd313bc08a4f290780dfa1cf9133eddf3bf3.tar.gz libbrandt-fc9fdd313bc08a4f290780dfa1cf9133eddf3bf3.zip |
make test_brandt ready for M+1st price auctions
-rw-r--r-- | test_brandt.c | 70 |
1 files changed, 59 insertions, 11 deletions
diff --git a/test_brandt.c b/test_brandt.c index ee53a0d..8a27748 100644 --- a/test_brandt.c +++ b/test_brandt.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "crypto.h" | 28 | #include "crypto.h" |
29 | #include "util.h" | 29 | #include "util.h" |
30 | 30 | ||
31 | #define MIN(A, B) ((A) < (B) ? (A) : (B)) | ||
31 | 32 | ||
32 | struct msg { | 33 | struct msg { |
33 | uint16_t sender; | 34 | uint16_t sender; |
@@ -55,26 +56,73 @@ static struct testcase tcase; | |||
55 | static struct BRANDT_Result * | 56 | static struct BRANDT_Result * |
56 | expected_outcome (uint16_t i) | 57 | expected_outcome (uint16_t i) |
57 | { | 58 | { |
59 | struct BRANDT_Result *ret = NULL; | ||
58 | int32_t highest_bidder = -1; | 60 | int32_t highest_bidder = -1; |
59 | int32_t highest_bid = -1; | 61 | int32_t highest_bid = -1; |
60 | struct BRANDT_Result *ret; | 62 | int32_t mpf_highest_bidder; |
63 | int32_t mpf_highest_bid; | ||
64 | int32_t prev_mpf_highest_bidder = -1; | ||
65 | uint16_t winners = MIN (tcase.m, tcase.n); | ||
66 | uint16_t cur_winner = 0; | ||
61 | 67 | ||
62 | for (uint16_t h = 0; h < tcase.n; h++) | 68 | if (0 == tcase.m) |
63 | { | 69 | { |
64 | if (tcase.bids[h] > highest_bid) | 70 | for (uint16_t h = 0; h < tcase.n; h++) |
71 | if (tcase.bids[h] > highest_bid) | ||
72 | highest_bid = tcase.bids[highest_bidder = h]; | ||
73 | |||
74 | if (!tcase.outcome_public && !(i == highest_bidder || i == tcase.n)) | ||
75 | return NULL; | ||
76 | |||
77 | ret = GNUNET_new (struct BRANDT_Result); | ||
78 | ret->bidder = highest_bidder; | ||
79 | ret->price = highest_bid; | ||
80 | ret->status = BRANDT_bidder_won; | ||
81 | return ret; | ||
82 | } | ||
83 | |||
84 | /* find M+1st highest bidder to determine selling price */ | ||
85 | for (uint16_t m = 0; m <= MIN (tcase.m, tcase.n - 1); m++) | ||
86 | { | ||
87 | for (uint16_t h = 0; h < tcase.n; h++) | ||
65 | { | 88 | { |
66 | highest_bid = tcase.bids[h]; | 89 | mpf_highest_bidder = -1; |
67 | highest_bidder = h; | 90 | mpf_highest_bid = -1; |
91 | if (tcase.bids[h] > mpf_highest_bid && | ||
92 | (-1 == prev_mpf_highest_bidder || | ||
93 | tcase.bids[h] < tcase.bids[prev_mpf_highest_bidder] || | ||
94 | h > prev_mpf_highest_bidder)) | ||
95 | mpf_highest_bid = tcase.bids[mpf_highest_bidder = h]; | ||
68 | } | 96 | } |
97 | prev_mpf_highest_bidder = mpf_highest_bidder; | ||
69 | } | 98 | } |
70 | 99 | ||
71 | if (!tcase.outcome_public && !(i == highest_bidder || i == tcase.n)) | 100 | /* for simplicity always locate the big block if we need to report at |
72 | return NULL; | 101 | * least one winner. with private outcome for losing bidders or winners |
102 | * only none or one element will be used respectively. */ | ||
103 | if (tcase.outcome_public || i == tcase.n || | ||
104 | tcase.bids[i] > mpf_highest_bid || | ||
105 | (tcase.bids[i] == mpf_highest_bid && i < mpf_highest_bidder)) | ||
106 | ret = GNUNET_new_array (winners, struct BRANDT_Result); | ||
73 | 107 | ||
74 | ret = GNUNET_new (struct BRANDT_Result); | 108 | /* report winners */ |
75 | ret->bidder = highest_bidder; | 109 | for (uint16_t h = 0; h < tcase.n; h++) |
76 | ret->price = highest_bid; | 110 | { |
77 | ret->status = BRANDT_bidder_won; | 111 | if (((tcase.bids[h] == mpf_highest_bid && h < mpf_highest_bidder) || |
112 | tcase.bids[h] > mpf_highest_bid) && /* h is a winner */ | ||
113 | (tcase.outcome_public || i == h || i == tcase.n)) /* needs report */ | ||
114 | { | ||
115 | if (cur_winner >= winners) | ||
116 | { | ||
117 | weprintf ("got too many winners"); | ||
118 | _exit (1); | ||
119 | } | ||
120 | ret[cur_winner].bidder = h; | ||
121 | ret[cur_winner].price = mpf_highest_bid; | ||
122 | ret[cur_winner].status = BRANDT_bidder_won; | ||
123 | cur_winner++; | ||
124 | } | ||
125 | } | ||
78 | return ret; | 126 | return ret; |
79 | } | 127 | } |
80 | 128 | ||