@@ -33,30 +33,160 @@ def test_short_repr_when_long(self):
33
33
output = short_repr (item )
34
34
assert output == "{'Eat more':...}"
35
35
36
- @pytest .mark .parametrize ("t1, t2, significant_digits, expected_result" ,
36
+ @pytest .mark .parametrize ("t1, t2, significant_digits, number_format_notation, expected_result" ,
37
37
[
38
- (10 , 10.0 , 5 , True ),
39
- (10 , 10.2 , 5 , ('10.00000' , '10.20000' )),
40
- (10 , 10.2 , 0 , True ),
41
- (Decimal (10 ), 10 , 0 , True ),
42
- (Decimal (10 ), 10 , 10 , True ),
43
- (Decimal (10 ), 10.0 , 0 , True ),
44
- (Decimal (10 ), 10.0 , 10 , True ),
45
- (Decimal ('10.0' ), 10.0 , 5 , True ),
46
- (Decimal ('10.01' ), 10.01 , 1 , True ),
47
- (Decimal ('10.01' ), 10.01 , 2 , True ),
48
- (Decimal ('10.01' ), 10.01 , 5 , True ),
49
- (Decimal ('10.01' ), 10.01 , 8 , True ),
50
- (Decimal ('10.010' ), 10.01 , 3 , True ),
51
- (Decimal ('100000.1' ), 100000.1 , 0 , True ),
52
- (Decimal ('100000.1' ), 100000.1 , 1 , True ),
53
- (Decimal ('100000.1' ), 100000.1 , 5 , True ),
54
- (Decimal ('100000' ), 100000.1 , 0 , True ),
55
- (Decimal ('100000' ), 100000.1 , 1 , ('100000.0' , '100000.1' )),
38
+ (10 , 10.0 , 5 , "f" , True ),
39
+ (10 , 10.0 , 5 , "e" , True ),
40
+ (10 , 10.2 , 5 , "f" , ('10.00000' , '10.20000' )),
41
+ (10 , 10.2 , 5 , "e" , ('1.00000e+1' , '1.02000e+1' )),
42
+ (10 , 10.2 , 0 , "f" , True ),
43
+ (10 , 10.2 , 0 , "e" , True ),
44
+ (Decimal (10 ), 10 , 0 , "f" , True ),
45
+ (Decimal (10 ), 10 , 0 , "e" , True ),
46
+ (Decimal (10 ), 10 , 10 , "f" , True ),
47
+ (Decimal (10 ), 10 , 10 , "e" , True ),
48
+ (Decimal (10 ), 10.0 , 0 , "f" , True ),
49
+ (Decimal (10 ), 10.0 , 0 , "e" , True ),
50
+ (Decimal (10 ), 10.0 , 10 , "f" , True ),
51
+ (Decimal (10 ), 10.0 , 10 , "e" , True ),
52
+ (Decimal ('10.0' ), 10.0 , 5 , "f" , True ),
53
+ (Decimal ('10.0' ), 10.0 , 5 , "e" , True ),
54
+ (Decimal ('10.01' ), 10.01 , 1 , "f" , True ),
55
+ (Decimal ('10.01' ), 10.01 , 1 , "e" , True ),
56
+ (Decimal ('10.01' ), 10.01 , 2 , "f" , True ),
57
+ (Decimal ('10.01' ), 10.01 , 2 , "e" , True ),
58
+ (Decimal ('10.01' ), 10.01 , 5 , "f" , True ),
59
+ (Decimal ('10.01' ), 10.01 , 5 , "e" , True ),
60
+ (Decimal ('10.01' ), 10.01 , 8 , "f" , True ),
61
+ (Decimal ('10.01' ), 10.01 , 8 , "e" , True ),
62
+ (Decimal ('10.010' ), 10.01 , 3 , "f" , True ),
63
+ (Decimal ('10.010' ), 10.01 , 3 , "e" , True ),
64
+ (Decimal ('100000.1' ), 100000.1 , 0 , "f" , True ),
65
+ (Decimal ('100000.1' ), 100000.1 , 0 , "e" , True ),
66
+ (Decimal ('100000.1' ), 100000.1 , 1 , "f" , True ),
67
+ (Decimal ('100000.1' ), 100000.1 , 1 , "e" , True ),
68
+ (Decimal ('100000.1' ), 100000.1 , 5 , "f" , True ),
69
+ (Decimal ('100000.1' ), 100000.1 , 5 , "e" , True ),
70
+ (Decimal ('100000' ), 100000.1 , 0 , "f" , True ),
71
+ (Decimal ('100000' ), 100000.1 , 0 , "e" , True ),
72
+ (Decimal ('100000' ), 100000.1 , 1 , "f" , ('100000.0' , '100000.1' )),
73
+ (Decimal ('100000' ), 100000.1 , 1 , "e" , True ),
74
+ (Decimal ('-100000' ), 100000.1 , 1 , "f" , ('-100000.0' , '100000.1' )),
75
+ (Decimal ('-100000' ), 100000.1 , 1 , "e" , ("-1.0e+5" ,"1.0e+5" )),
76
+ (0 , 0.0 , 5 , "f" , True ),
77
+ (0 , 0.0 , 5 , "e" , True ),
78
+ (0 , 0.2 , 5 , "f" , ('0.00000' , '0.20000' )),
79
+ (0 , 0.2 , 5 , "e" , ('0.00000e+0' , '2.00000e-1' )),
80
+ (0 , 0.2 , 0 , "f" , True ),
81
+ (0 , 0.2 , 0 , "e" , True ),
82
+ (Decimal (0 ), 0 , 0 , "f" , True ),
83
+ (Decimal (0 ), 0 , 0 , "e" , True ),
84
+ (Decimal (0 ), 0 , 10 , "f" , True ),
85
+ (Decimal (0 ), 0 , 10 , "e" , True ),
86
+ (Decimal (0 ), 0.0 , 0 , "f" , True ),
87
+ (Decimal (0 ), 0.0 , 0 , "e" , True ),
88
+ (Decimal (0 ), 0.0 , 10 , "f" , True ),
89
+ (Decimal (0 ), 0.0 , 10 , "e" , True ),
90
+ (Decimal ('0.0' ), 0.0 , 5 , "f" , True ),
91
+ (Decimal ('0.0' ), 0.0 , 5 , "e" , True ),
92
+ (Decimal ('0.01' ), 0.01 , 1 , "f" , True ),
93
+ (Decimal ('0.01' ), 0.01 , 1 , "e" , True ),
94
+ (Decimal ('0.01' ), 0.01 , 2 , "f" , True ),
95
+ (Decimal ('0.01' ), 0.01 , 2 , "e" , True ),
96
+ (Decimal ('0.01' ), 0.01 , 5 , "f" , True ),
97
+ (Decimal ('0.01' ), 0.01 , 5 , "e" , True ),
98
+ (Decimal ('0.01' ), 0.01 , 8 , "f" , True ),
99
+ (Decimal ('0.01' ), 0.01 , 8 , "e" , True ),
100
+ (Decimal ('0.010' ), 0.01 , 3 , "f" , True ),
101
+ (Decimal ('0.010' ), 0.01 , 3 , "e" , True ),
102
+ (Decimal ('0.00002' ), 0.00001 , 0 , "f" , True ),
103
+ (Decimal ('0.00002' ), 0.00001 , 0 , "e" , True ),
104
+ (Decimal ('0.00002' ), 0.00001 , 1 , "f" , True ),
105
+ (Decimal ('0.00002' ), 0.00001 , 1 , "e" , True ),
106
+ (Decimal ('0.00002' ), 0.00001 , 5 , "f" , ('0.00002' , '0.00001' )),
107
+ (Decimal ('0.00002' ), 0.00001 , 5 , "e" , ('2.00000e-5' , '1.00000e-5' )),
108
+ (Decimal ('0.00002' ), 0.00001 , 6 , "f" , ('0.000020' , '0.000010' )),
109
+ (Decimal ('0.00002' ), 0.00001 , 6 , "e" , ('2.000000e-5' , '1.000000e-5' )),
110
+ (Decimal ('0' ), 0.1 , 0 , "f" , True ),
111
+ (Decimal ('0' ), 0.1 , 0 , "e" , True ),
112
+ (Decimal ('0' ), 0.1 , 1 , "f" , ('0.0' , '0.1' )),
113
+ (Decimal ('0' ), 0.1 , 1 , "e" , ('0.0e+0' , '1.0e-1' )),
114
+ (- 0 , 0.0 , 5 , "f" , True ),
115
+ (- 0 , 0.0 , 5 , "e" , True ),
116
+ (- 0 , 0.2 , 5 , "f" , ('0.00000' , '0.20000' )),
117
+ (- 0 , 0.2 , 5 , "e" , ('0.00000e+0' , '2.00000e-1' )),
118
+ (- 0 , 0.2 , 0 , "f" , True ),
119
+ (- 0 , 0.2 , 0 , "e" , True ),
120
+ (Decimal (- 0 ), 0 , 0 , "f" , True ),
121
+ (Decimal (- 0 ), 0 , 0 , "e" , True ),
122
+ (Decimal (- 0 ), 0 , 10 , "f" , True ),
123
+ (Decimal (- 0 ), 0 , 10 , "e" , True ),
124
+ (Decimal (- 0 ), 0.0 , 0 , "f" , True ),
125
+ (Decimal (- 0 ), 0.0 , 0 , "e" , True ),
126
+ (Decimal (- 0 ), 0.0 , 10 , "f" , True ),
127
+ (Decimal (- 0 ), 0.0 , 10 , "e" , True ),
128
+ (Decimal ('-0.0' ), 0.0 , 5 , "f" , True ),
129
+ (Decimal ('-0.0' ), 0.0 , 5 , "e" , True ),
130
+ (Decimal ('-0.01' ), 0.01 , 1 , "f" , True ),
131
+ (Decimal ('-0.01' ), 0.01 , 1 , "e" , True ),
132
+ (Decimal ('-0.01' ), 0.01 , 2 , "f" , ('-0.01' , '0.01' )),
133
+ (Decimal ('-0.01' ), 0.01 , 2 , "e" , ('-1.00e-2' , '1.00e-2' )),
134
+ (Decimal ('-0.00002' ), 0.00001 , 0 , "f" , True ),
135
+ (Decimal ('-0.00002' ), 0.00001 , 0 , "e" , True ),
136
+ (Decimal ('-0.00002' ), 0.00001 , 1 , "f" , True ),
137
+ (Decimal ('-0.00002' ), 0.00001 , 1 , "e" , True ),
138
+ (Decimal ('-0.00002' ), 0.00001 , 5 , "f" , ('-0.00002' , '0.00001' )),
139
+ (Decimal ('-0.00002' ), 0.00001 , 5 , "e" , ('-2.00000e-5' , '1.00000e-5' )),
140
+ (Decimal ('-0.00002' ), 0.00001 , 6 , "f" , ('-0.000020' , '0.000010' )),
141
+ (Decimal ('-0.00002' ), 0.00001 , 6 , "e" , ('-2.000000e-5' , '1.000000e-5' )),
142
+ (Decimal ('-0' ), 0.1 , 0 , "f" , True ),
143
+ (Decimal ('-0' ), 0.1 , 0 , "e" , True ),
144
+ (Decimal ('-0' ), 0.1 , 1 , "f" , ('0.0' , '0.1' )),
145
+ (Decimal ('-0' ), 0.1 , 1 , "e" , ('0.0e+0' , '1.0e-1' )),
56
146
])
57
- def test_number_to_string_decimal_digits (self , t1 , t2 , significant_digits , expected_result ):
58
- st1 = number_to_string (t1 , significant_digits = significant_digits , number_format_notation = "f" )
59
- st2 = number_to_string (t2 , significant_digits = significant_digits , number_format_notation = "f" )
147
+ def test_number_to_string_decimal_digits (self , t1 , t2 , significant_digits , number_format_notation , expected_result ):
148
+ st1 = number_to_string (t1 , significant_digits = significant_digits , number_format_notation = number_format_notation )
149
+ st2 = number_to_string (t2 , significant_digits = significant_digits , number_format_notation = number_format_notation )
150
+ if expected_result is True :
151
+ assert st1 == st2
152
+ else :
153
+ assert st1 == expected_result [0 ]
154
+ assert st2 == expected_result [1 ]
155
+
156
+ @pytest .mark .parametrize ("t1, t2, significant_digits, number_format_notation, expected_result" ,
157
+ [
158
+ (10j , 10.0j , 5 , "f" , True ),
159
+ (10j , 10.0j , 5 , "e" , True ),
160
+ (4 + 10j , 4.0000002 + 10.0000002j , 5 , "f" , True ),
161
+ (4 + 10j , 4.0000002 + 10.0000002j , 5 , "e" , True ),
162
+ (4 + 10j , 4.0000002 + 10.0000002j , 7 , "f" , ('4.0000000+10.0000000j' , '4.0000002+10.0000002j' )),
163
+ (4 + 10j , 4.0000002 + 10.0000002j , 7 , "e" , ('4.0000000e+0+1.0000000e+1j' , '4.0000002e+0+1.0000000e+1j' )),
164
+ (0.00002 + 0.00002j , 0.00001 + 0.00001j , 0 , "f" , True ),
165
+ (0.00002 + 0.00002j , 0.00001 + 0.00001j , 0 , "e" , True ),
166
+ (0.00002 + 0.00002j , 0.00001 + 0.00001j , 5 , "f" , ('0.00002+0.00002j' , '0.00001+0.00001j' )),
167
+ (0.00002 + 0.00002j , 0.00001 + 0.00001j , 5 , "e" , ('2.00000e-5+2.00000e-5j' , '1.00000e-5+1.00000e-5j' )),
168
+ (- 0.00002 - 0.00002j , 0.00001 + 0.00001j , 0 , "f" , True ),
169
+ (- 0.00002 - 0.00002j , 0.00001 + 0.00001j , 0 , "e" , True ),
170
+ (10j , 10.2j , 5 , "f" , ('0.00000+10.00000j' , '0.00000+10.20000j' )),
171
+ (10j , 10.2j , 5 , "e" , ('0.00000e+0+1.00000e+1j' , '0.00000e+0+1.02000e+1j' )),
172
+ (10j , 10.2j , 0 , "f" , True ),
173
+ (10j , 10.2j , 0 , "e" , True ),
174
+ (0j , 0.0j , 5 , "f" , True ),
175
+ (0j , 0.0j , 5 , "e" , True ),
176
+ (0j , 0.2j , 5 , "f" , ('0.00000' , '0.00000+0.20000j' )),
177
+ (0j , 0.2j , 5 , "e" , ('0.00000e+0' , '0.00000e+0+2.00000e-1j' )),
178
+ (0j , 0.2j , 0 , "f" , True ),
179
+ (0j , 0.2j , 0 , "e" , True ),
180
+ (- 0j , 0.0j , 5 , "f" , True ),
181
+ (- 0j , 0.0j , 5 , "e" , True ),
182
+ (- 0j , 0.2j , 5 , "f" , ('0.00000' , '0.00000+0.20000j' )),
183
+ (- 0j , 0.2j , 5 , "e" , ('0.00000e+0' , '0.00000e+0+2.00000e-1j' )),
184
+ (- 0j , 0.2j , 0 , "f" , True ),
185
+ (- 0j , 0.2j , 0 , "e" , True ),
186
+ ])
187
+ def test_number_to_string_complex_digits (self , t1 , t2 , significant_digits , number_format_notation , expected_result ):
188
+ st1 = number_to_string (t1 , significant_digits = significant_digits , number_format_notation = number_format_notation )
189
+ st2 = number_to_string (t2 , significant_digits = significant_digits , number_format_notation = number_format_notation )
60
190
if expected_result is True :
61
191
assert st1 == st2
62
192
else :
0 commit comments