| 1 | #include "TimeSeries/deserialize.h" |
| 2 | #include "lut.h" |
| 3 | #include <math.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <stdio.h> |
| 6 | #include "Util/utils.h" |
| 7 | |
| 8 | void t_deserialize1() |
| 9 | { |
| 10 | // decode sample_byCols.bin into the toy dataset (4 customers, 3 sample points) |
| 11 | const char* ifName = "../data/test/sample_byCols.bin"; |
| 12 | |
| 13 | // check 'header' |
| 14 | uint32_t nbSeries = get_nbSeries(ifName); |
| 15 | LUT_ASSERT(nbSeries == 4); |
| 16 | uint32_t tsLength = get_tsLength(ifName); |
| 17 | LUT_ASSERT(tsLength == 13); //3*3+4 |
| 18 | |
| 19 | uint32_t ranks[] = |
| 20 | { |
| 21 | 0, 2, 1, 3 |
| 22 | }; |
| 23 | PowerCurve* powerCurves = deserialize(ifName, NULL, ranks, nbSeries); |
| 24 | |
| 25 | Real epsilon = 0.1; //epsilon = 0.1 because raw powers are truncated |
| 26 | |
| 27 | LUT_ASSERT(powerCurves[0].ID == 12301); |
| 28 | LUT_ASSERT(fabs(powerCurves[0].values[0] - 23.051) < epsilon); |
| 29 | LUT_ASSERT(fabs(powerCurves[0].values[1] - 33.052) < epsilon); |
| 30 | LUT_ASSERT(fabs(powerCurves[0].values[2] - 43.053) < epsilon); |
| 31 | |
| 32 | LUT_ASSERT(powerCurves[1].ID == 1313); |
| 33 | LUT_ASSERT(fabs(powerCurves[1].values[0] - 50.05) < epsilon); |
| 34 | LUT_ASSERT(fabs(powerCurves[1].values[1] - 51.05) < epsilon); |
| 35 | LUT_ASSERT(fabs(powerCurves[1].values[2] - 52.05) < epsilon); |
| 36 | |
| 37 | LUT_ASSERT(powerCurves[2].ID == 50000); |
| 38 | LUT_ASSERT(fabs(powerCurves[2].values[0] - 150.321) < epsilon); |
| 39 | LUT_ASSERT(fabs(powerCurves[2].values[1] - 160.322) < epsilon); |
| 40 | LUT_ASSERT(fabs(powerCurves[2].values[2] - 140.323) < epsilon); |
| 41 | |
| 42 | LUT_ASSERT(powerCurves[3].ID == 6300); |
| 43 | LUT_ASSERT(fabs(powerCurves[3].values[0] - 500.30) < epsilon); |
| 44 | LUT_ASSERT(fabs(powerCurves[3].values[1] - 501.31) < epsilon); |
| 45 | LUT_ASSERT(fabs(powerCurves[3].values[2] - 502.32) < epsilon); |
| 46 | |
| 47 | for (int i = 0; i < nbSeries; i++) |
| 48 | free(powerCurves[i].values); |
| 49 | free(powerCurves); |
| 50 | } |
| 51 | |
| 52 | void t_deserialize2() |
| 53 | { |
| 54 | // decode sample_byRows.bin into the toy dataset (4 customers, 3 sample points) |
| 55 | const char* ifName = "../data/test/sample_byRows.bin"; |
| 56 | |
| 57 | // check 'header' |
| 58 | uint32_t nbSeries = get_nbSeries(ifName); |
| 59 | LUT_ASSERT(nbSeries == 4); |
| 60 | uint32_t tsLength = get_tsLength(ifName); |
| 61 | LUT_ASSERT(tsLength == 13); //3*3+4 |
| 62 | |
| 63 | uint32_t ranks[] = |
| 64 | { |
| 65 | 0, 2, 1, 3 |
| 66 | }; |
| 67 | PowerCurve* powerCurves = deserialize(ifName, NULL, ranks, nbSeries); |
| 68 | |
| 69 | Real epsilon = 0.1; //epsilon = 0.1 because raw powers are truncated |
| 70 | |
| 71 | LUT_ASSERT(powerCurves[0].ID == 12301); |
| 72 | LUT_ASSERT(fabs(powerCurves[0].values[0]/100.0-3 - 23.051) < epsilon); |
| 73 | LUT_ASSERT(fabs(powerCurves[0].values[1]/100.0-3 - 33.052) < epsilon); |
| 74 | LUT_ASSERT(fabs(powerCurves[0].values[2]/100.0-3 - 43.053) < epsilon); |
| 75 | |
| 76 | LUT_ASSERT(powerCurves[1].ID == 1313); |
| 77 | LUT_ASSERT(fabs(powerCurves[1].values[0]/100.0-3 - 50.05) < epsilon); |
| 78 | LUT_ASSERT(fabs(powerCurves[1].values[1]/100.0-3 - 51.05) < epsilon); |
| 79 | LUT_ASSERT(fabs(powerCurves[1].values[2]/100.0-3 - 52.05) < epsilon); |
| 80 | |
| 81 | LUT_ASSERT(powerCurves[2].ID == 50000); |
| 82 | LUT_ASSERT(fabs(powerCurves[2].values[0]/100.0-3 - 150.321) < epsilon); |
| 83 | LUT_ASSERT(fabs(powerCurves[2].values[1]/100.0-3 - 160.322) < epsilon); |
| 84 | LUT_ASSERT(fabs(powerCurves[2].values[2]/100.0-3 - 140.323) < epsilon); |
| 85 | |
| 86 | LUT_ASSERT(powerCurves[3].ID == 6300); |
| 87 | LUT_ASSERT(fabs(powerCurves[3].values[0]/100.0-3 - 500.30) < epsilon); |
| 88 | LUT_ASSERT(fabs(powerCurves[3].values[1]/100.0-3 - 501.31) < epsilon); |
| 89 | LUT_ASSERT(fabs(powerCurves[3].values[2]/100.0-3 - 502.32) < epsilon); |
| 90 | |
| 91 | for (int i = 0; i < nbSeries; i++) |
| 92 | free(powerCurves[i].values); |
| 93 | free(powerCurves); |
| 94 | } |