OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import "package:expect/expect.dart"; | |
6 | |
7 bool TestAssociativity(bool chop) { | |
Florian Schneider
2016/08/03 23:35:58
For testing here maybe pass in a function chop (or
regis
2016/08/04 18:22:31
Done.
| |
8 // Example from https://en.wikipedia.org/wiki/Floating_point | |
9 // Test that (a + b) + c == a + (b + c). | |
10 double a = chop ? 1234.567.p : 1234.567; // Chop literals. | |
11 double b = chop ? 45.67834.p : 45.67834; | |
12 double c = chop ? 0.0004.p : 0.0004; | |
13 double x = (a + b) + c; // Chop result of multiplication or division only. | |
14 double y = a + (b + c); | |
15 print("x: $x"); | |
16 print("y: $y"); | |
17 return x == y; | |
18 } | |
19 | |
20 bool TestDistributivity(bool chop) { | |
21 // Example from https://en.wikipedia.org/wiki/Floating_point | |
22 // Test that (a + b)*c == a*c + b*c. | |
23 double a = chop ? 1234.567.p : 1234.567; // Chop literals. | |
24 double b = chop ? 1.234567.p : 1.234567; | |
25 double c = chop ? 3.333333.p : 3.333333; | |
26 double x = chop ? ((a + b)*c).p : (a + b)*c; // Chop result of multiplication . | |
27 double y = (chop ? (a*c).p : (a*c)) + (chop ? (b*c).p : (b*c)); | |
28 print("x: $x"); | |
29 print("y: $y"); | |
30 return x == y; | |
31 } | |
32 | |
33 main() { | |
34 print("without chopping fractional bits:"); | |
35 Expect.isFalse(TestAssociativity(false)); | |
Florian Schneider
2016/08/03 23:35:58
e.g. Expect.isFalse(TestAssociativity((x) => x));
regis
2016/08/04 18:22:31
Done.
| |
36 Expect.isFalse(TestDistributivity(false)); | |
37 print("with chopping fractional bits:"); | |
38 Expect.isTrue(TestAssociativity(true)); | |
Florian Schneider
2016/08/03 23:35:58
e.g. Expect.isTrue(TestAssociativity((x) => x.p));
regis
2016/08/04 18:22:31
Done.
| |
39 Expect.isTrue(TestDistributivity(true)); | |
40 } | |
OLD | NEW |