|
10 | 10 | #include "cantera/transport/TransportData.h" |
11 | 11 |
|
12 | 12 | using namespace Cantera; |
| 13 | +using namespace YAML; |
| 14 | + |
| 15 | +TEST(YamlWriter, formatDouble) |
| 16 | +{ |
| 17 | + AnyMap m; |
| 18 | + int count; |
| 19 | + float delta; |
| 20 | + |
| 21 | + // check least significant digit |
| 22 | + // default precision is 15 (see AnyMap.cpp::getPrecicion) |
| 23 | + delta = 1.e-15; |
| 24 | + count = 0; |
| 25 | + for (int i = -9; i < 10; i += 2) { |
| 26 | + m["a"] = 4. + i * delta; |
| 27 | + if (i < -5 || i > 4) { |
| 28 | + // round away from 4. |
| 29 | + EXPECT_NE(m.toYamlString(), "a: 4.0\n"); |
| 30 | + } else { |
| 31 | + // round towards 4. |
| 32 | + EXPECT_EQ(m.toYamlString(), "a: 4.0\n"); |
| 33 | + count++; |
| 34 | + } |
| 35 | + } |
| 36 | + EXPECT_EQ(count, 5); // only checking even multiples of delta |
| 37 | + |
| 38 | + // check edge cases |
| 39 | + m["a"] = -1061.793215682400; |
| 40 | + EXPECT_EQ(m.toYamlString(), "a: -1061.7932156824\n"); |
| 41 | +} |
| 42 | + |
| 43 | +TEST(YamlWriter, formatDoubleExp) |
| 44 | +{ |
| 45 | + AnyMap m; |
| 46 | + int count; |
| 47 | + float delta; |
| 48 | + |
| 49 | + // check least significant digit |
| 50 | + // default precision is 15 (see AnyMap.cpp::getPrecicion) |
| 51 | + delta = 1.e-5; |
| 52 | + count = 0; |
| 53 | + for (int i = -9; i < 10; i += 2) { |
| 54 | + m["a"] = 4.e10 + i * delta; |
| 55 | + if (i < -5 || i > 4) { |
| 56 | + // round away from 4. |
| 57 | + EXPECT_NE(m.toYamlString(), "a: 4.0e+10\n"); |
| 58 | + } else { |
| 59 | + // round towards 4. |
| 60 | + EXPECT_EQ(m.toYamlString(), "a: 4.0e+10\n"); |
| 61 | + count++; |
| 62 | + } |
| 63 | + } |
| 64 | + EXPECT_EQ(count, 5); // only checking even multiples of delta |
| 65 | + |
| 66 | + // check edge cases |
| 67 | + m["a"] = 1.629771953878800e+13; |
| 68 | + EXPECT_EQ(m.toYamlString(), "a: 1.6297719538788e+13\n"); |
| 69 | +} |
13 | 70 |
|
14 | 71 | TEST(YamlWriter, thermoDef) |
15 | 72 | { |
|
0 commit comments