33
44
55def test_tau_50 ():
6- tokens_per_entity = [('a' , 3.0 ), ('b' , 2 ), ('c' , 1 )]
6+ tokens_per_entity = [(3.0 , ), (2 , ), (1 , )]
77 tau_index , tau_market_share = compute_tau (tokens_per_entity , circulation = 6 , threshold = 0.5 )
88 assert tau_index == 1
99 assert tau_market_share == 0.5
1010
11- tokens_per_entity = [('a' , 3 ), ('b' , 2 ), ('c' , 1 ), ('d' , 1 ), ('e' , 1 ), ('f' , 1 )]
11+ tokens_per_entity = [(3 , ), (2 , ), (1 , ), (1 , ), (1 , ), (1 , )]
1212 tau_index , tau_market_share = compute_tau (tokens_per_entity , circulation = 9 , threshold = 0.5 )
1313 assert tau_index == 2
1414 assert round (tau_market_share , 2 ) == 0.56
1515
16- tokens_per_entity = [('a' , 1 )]
16+ tokens_per_entity = [(1 , )]
1717 tau_index , tau_market_share = compute_tau (tokens_per_entity , circulation = 1 , threshold = 0.5 )
1818 assert tau_index == 1
1919 assert tau_market_share == 1
2020
2121
2222def test_tau_33 ():
23- tokens_per_entity = [('a' , 3.0 ), ('b' , 2 ), ('c' , 1 )]
23+ tokens_per_entity = [(3.0 , ), (2 , ), (1 , )]
2424 tau_index , tau_market_share = compute_tau (tokens_per_entity , circulation = 6 , threshold = 0.33 )
2525 assert tau_index == 1
2626 assert tau_market_share == 0.5
2727
28- tokens_per_entity = [('a' , 3 ), ('b' , 2 ), ('c' , 1 ), ('d' , 1 ), ('e' , 1 ), ('f' , 1 )]
28+ tokens_per_entity = [(3 , ), (2 , ), (1 , ), (1 , ), (1 , ), (1 , )]
2929 tau_index , tau_market_share = compute_tau (tokens_per_entity , circulation = 9 , threshold = 0.33 )
3030 assert tau_index == 1
3131 assert round (tau_market_share , 2 ) == 0.33
3232
33- tokens_per_entity = [('a' , 1 )]
33+ tokens_per_entity = [(1 , )]
3434 tau_index , tau_market_share = compute_tau (tokens_per_entity , circulation = 1 , threshold = 0.33 )
3535 assert tau_index == 1
3636 assert tau_market_share == 1
3737
3838
3939def test_tau_66 ():
40- tokens_per_entity = [('a' , 3.0 ), ('b' , 2 ), ('c' , 1 )]
40+ tokens_per_entity = [(3.0 , ), (2 , ), (1 , )]
4141 tau_index , tau_market_share = compute_tau (tokens_per_entity , circulation = 6 , threshold = 0.66 )
4242 assert tau_index == 2
4343 assert round (tau_market_share , 2 ) == 0.83
4444
45- tokens_per_entity = [('a' , 3 ), ('b' , 2 ), ('c' , 1 ), ('d' , 1 ), ('e' , 1 ), ('f' , 1 )]
45+ tokens_per_entity = [(3 , ), (2 , ), (1 , ), (1 , ), (1 , ), (1 , )]
4646 tau_index , tau_market_share = compute_tau (tokens_per_entity , circulation = 9 , threshold = 0.66 )
4747 assert tau_index == 3
4848 assert round (tau_market_share , 2 ) == 0.67
4949
50- tokens_per_entity = [('a' , 1 )]
50+ tokens_per_entity = [(1 , )]
5151 tau_index , tau_market_share = compute_tau (tokens_per_entity , circulation = 1 , threshold = 0.66 )
5252 assert tau_index == 1
5353 assert tau_market_share == 1
@@ -58,19 +58,19 @@ def test_gini():
5858 Ensure that the results of the compute_gini function are consistent with online calculators,
5959 such as https://goodcalculators.com/gini-coefficient-calculator/ (5 decimal accuracy)
6060 """
61- tokens_per_entity = [('a' , 3.0 ), ('b' , 2 ), ('c' , 1 )]
61+ tokens_per_entity = [(3.0 , ), (2 , ), (1 , )]
6262 gini = compute_gini (tokens_per_entity , circulation = 6 )
6363 assert round (gini , 5 ) == 0.22222
6464
65- tokens_per_entity = [('a' , 3 ), ('b' , 2 ), ('c' , 1 ), ('d' , 1 ), ('e' , 1 ), ('f' , 1 )]
65+ tokens_per_entity = [(3 , ), (2 , ), (1 , ), (1 , ), (1 , ), (1 , )]
6666 gini = compute_gini (tokens_per_entity , circulation = 9 )
6767 assert round (gini , 5 ) == 0.24074
6868
69- tokens_per_entity = [('a' , 1 )]
69+ tokens_per_entity = [(1 , )]
7070 gini = compute_gini (tokens_per_entity , circulation = 1 )
7171 assert gini == 0
7272
73- tokens_per_entity = [('a' , 1 ), ('b' , 1 ), ('c' , 1 )]
73+ tokens_per_entity = [(1 , ), (1 , ), (1 , )]
7474 gini = compute_gini (tokens_per_entity , circulation = 3 )
7575 assert round (gini , 5 ) == 0 # Note that this test case fails if we don't round, because of floating point errors
7676
@@ -80,19 +80,19 @@ def test_hhi():
8080 Ensure that the results of the compute_hhi function are consistent with online calculators,
8181 such as https://www.unclaw.com/chin/teaching/antitrust/herfindahl.htm
8282 """
83- tokens_per_entity = [('a' , 3.0 ), ('b' , 2 ), ('c' , 1 )]
83+ tokens_per_entity = [(3.0 , ), (2 , ), (1 , )]
8484 hhi = compute_hhi (tokens_per_entity , circulation = 6 )
8585 assert round (hhi ) == 3889
8686
87- tokens_per_entity = [('a' , 3 ), ('b' , 2 ), ('c' , 1 ), ('d' , 1 ), ('e' , 1 ), ('f' , 1 )]
87+ tokens_per_entity = [(3 , ), (2 , ), (1 , ), (1 , ), (1 , ), (1 , )]
8888 hhi = compute_hhi (tokens_per_entity , circulation = 9 )
8989 assert round (hhi ) == 2099
9090
91- tokens_per_entity = [('a' , 1 )]
91+ tokens_per_entity = [(1 , )]
9292 hhi = compute_hhi (tokens_per_entity , circulation = 1 )
9393 assert round (hhi ) == 10000
9494
95- tokens_per_entity = [('a' , 1 ), ('b' , 1 ), ('c' , 1 )]
95+ tokens_per_entity = [(1 , ), (1 , ), (1 , )]
9696 hhi = compute_hhi (tokens_per_entity , circulation = 3 )
9797 assert round (hhi ) == 3333
9898
@@ -102,51 +102,51 @@ def test_shannon_entropy():
102102 Ensure that the results of the compute_shannon_entropy function are consistent with online calculators,
103103 such as: https://www.omnicalculator.com/statistics/shannon-entropy
104104 """
105- tokens_per_entity = [('a' , 3.0 ), ('b' , 2 ), ('c' , 1 )]
105+ tokens_per_entity = [(3.0 , ), (2 , ), (1 , )]
106106 entropy = compute_shannon_entropy (tokens_per_entity , circulation = 6 )
107107 assert round (entropy , 3 ) == 1.459
108108
109- tokens_per_entity = [('a' , 3 ), ('b' , 2 ), ('c' , 1 ), ('d' , 1 ), ('e' , 1 ), ('f' , 1 )]
109+ tokens_per_entity = [(3 , ), (2 , ), (1 , ), (1 , ), (1 , ), (1 , )]
110110 entropy = compute_shannon_entropy (tokens_per_entity , circulation = 9 )
111111 assert round (entropy , 3 ) == 2.419
112112
113- tokens_per_entity = [('a' , 1 )]
113+ tokens_per_entity = [(1 , )]
114114 entropy = compute_shannon_entropy (tokens_per_entity , circulation = 1 )
115115 assert entropy == 0
116116
117- tokens_per_entity = [('a' , 1 ), ('b' , 1 ), ('c' , 1 )]
117+ tokens_per_entity = [(1 , ), (1 , ), (1 , )]
118118 entropy = compute_shannon_entropy (tokens_per_entity , circulation = 3 )
119119 assert round (entropy , 3 ) == 1.585
120120
121121
122122def test_total_entities ():
123- tokens_per_entity = [('a' , 3.0 ), ('b' , 2 ), ('c' , 1 )]
123+ tokens_per_entity = [(3.0 , ), (2 , ), (1 , )]
124124 total_entities = compute_total_entities (tokens_per_entity , circulation = 6 )
125125 assert total_entities == 3
126126
127- tokens_per_entity = [('a' , 3 ), ('b' , 2 ), ('c' , 1 ), ('d' , 1 ), ('e' , 1 ), ('f' , 1 )]
127+ tokens_per_entity = [(3 , ), (2 , ), (1 , ), (1 , ), (1 , ), (1 , )]
128128 total_entities = compute_total_entities (tokens_per_entity , circulation = 9 )
129129 assert total_entities == 6
130130
131- tokens_per_entity = [('a' , 1 )]
131+ tokens_per_entity = [(1 , )]
132132 total_entities = compute_total_entities (tokens_per_entity , circulation = 1 )
133133 assert total_entities == 1
134134
135135
136136def test_compute_max_power_ratio ():
137- tokens_per_entity = [('a' , 3.0 ), ('b' , 2 ), ('c' , 1 )]
137+ tokens_per_entity = [(3.0 , ), (2 , ), (1 , )]
138138 max_mpr = compute_max_power_ratio (tokens_per_entity , circulation = 6 )
139139 assert max_mpr == 0.5
140140
141- tokens_per_entity = [('a' , 3 ), ('b' , 2 ), ('c' , 1 ), ('d' , 1 ), ('e' , 1 ), ('f' , 1 )]
141+ tokens_per_entity = [(3 , ), (2 , ), (1 , ), (1 , ), (1 , ), (1 , )]
142142 max_mpr = compute_max_power_ratio (tokens_per_entity , circulation = 9 )
143143 assert max_mpr == 1 / 3
144144
145- tokens_per_entity = [('a' , 1 )]
145+ tokens_per_entity = [(1 , )]
146146 max_mpr = compute_max_power_ratio (tokens_per_entity , circulation = 1 )
147147 assert max_mpr == 1
148148
149- tokens_per_entity = [('a' , 1 ), ('b' , 1 ), ('c' , 1 )]
149+ tokens_per_entity = [(1 , ), (1 , ), (1 , )]
150150 max_mpr = compute_max_power_ratio (tokens_per_entity , circulation = 3 )
151151 assert max_mpr == 1 / 3
152152
@@ -158,22 +158,22 @@ def test_compute_theil_index():
158158 """
159159 decimals = 3
160160
161- tokens_per_entity = [('a' , 3.0 ), ('b' , 2 ), ('c' , 1 )]
161+ tokens_per_entity = [(3.0 , ), (2 , ), (1 , )]
162162 theil_t = compute_theil_index (tokens_per_entity , 6 )
163163 assert round (theil_t , decimals ) == 0.087
164164
165- tokens_per_entity = [('a' , 3 ), ('b' , 2 ), ('c' , 1 ), ('d' , 1 ), ('e' , 1 ), ('f' , 1 )]
165+ tokens_per_entity = [(3 , ), (2 , ), (1 , ), (1 , ), (1 , ), (1 , )]
166166 theil_t = compute_theil_index (tokens_per_entity , 9 )
167167 assert round (theil_t , decimals ) == 0.115
168168
169- tokens_per_entity = {( 'a' , 432 ), ('b' , 0 ), ('c' , 0 ), ('d' , 0 )}
169+ tokens_per_entity = [( 432 , ), (0 , ), (0 , ), (0 , )]
170170 theil_t = compute_theil_index (tokens_per_entity , 432 )
171171 assert round (theil_t , decimals ) == 1.386
172172
173- tokens_per_entity = {( 'a' , 432 )}
173+ tokens_per_entity = [( 432 , )]
174174 theil_t = compute_theil_index (tokens_per_entity , 432 )
175175 assert round (theil_t , decimals ) == 0
176176
177- tokens_per_entity = {}
177+ tokens_per_entity = []
178178 theil_t = compute_theil_index (tokens_per_entity , 432 )
179179 assert theil_t == 0
0 commit comments