Commit | Line | Data |
---|---|---|
81923e5c BA |
1 | #include "lut.h" |
2 | #include <stdlib.h> | |
3 | #include "MPI_Communication/unpack.h" | |
4 | #include "Util/types.h" | |
5 | #include <stdint.h> | |
6 | #include <string.h> | |
7 | #include "Util/utils.h" | |
8 | ||
9 | // Work_t | |
10 | void t_unpack1() | |
11 | { | |
12 | // Hard-coded packed work | |
13 | unsigned char packedWork[] = | |
14 | { | |
15 | // --> ../data/inputTest.bin | |
16 | 46,46,47,100,97,116,97,47,105,110,112,117,116,84,101,115,116,46,98,105,110, | |
17 | // continue with 256 - strlen("../data/inputTest.bin") zeros... | |
18 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
19 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
20 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
21 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
22 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
23 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
24 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
25 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
26 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
27 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
28 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
29 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
30 | // --> 5, {ranks}+0,0, 15, 0 on 4-bytes integers little-endian | |
31 | 5,0,0,0, 0,0,0,0, 11,3,12,0, 42,17,2,32, 123,0,0,0, 10,0,77,51, 0,0,0,0, 0,0,0,0, | |
32 | 15,0,0,0, 0,0,0,0, 2,0,0,0 | |
33 | }; | |
34 | ||
35 | uint32_t nbSeriesInChunk = 7; | |
36 | Work_t* work = unpack_work(packedWork, nbSeriesInChunk); | |
37 | ||
38 | LUT_ASSERT(strcmp(work->inputFileName, "../data/inputTest.bin") == 0); | |
39 | LUT_ASSERT(work->nbSeries == 5); | |
40 | uint32_t ranks[] = | |
41 | { | |
42 | 0, | |
43 | 12*65536 + 3*256+11, | |
44 | 32*16777216 + 2*65536 + 17*256 + 42, | |
45 | 123, | |
46 | 51*16777216 + 77*65536 + 0*256 + 10 | |
47 | }; | |
48 | for (uint32_t i=0; i < work->nbSeries; i++) | |
49 | { | |
50 | LUT_ASSERT(work->ranks[i] == ranks[i]); | |
51 | } | |
52 | LUT_ASSERT(work->nbClusters == 15); | |
53 | LUT_ASSERT(work->clustOnMedoids == 0); | |
54 | LUT_ASSERT(work->p_for_dissims == 2); | |
55 | ||
56 | free_work(work); | |
57 | } | |
58 | ||
59 | // Result_t | |
60 | void t_unpack2() { | |
61 | ||
62 | // Hard-coded packed result | |
63 | unsigned char packedResult[] = | |
64 | { | |
65 | // 5, {medoids_ID}, {medoids_ranks} | |
66 | 5,0,0,0, | |
67 | 11,13,15,0, 11,0,0,0, 42,14,0,17, 7,0,123,0, 10,0,0,51, | |
68 | 32,0,5,0, 4,11,0,0, 42,0,0,23, 77,5,35,0, 10,1,1,1 | |
69 | }; | |
70 | ||
71 | Result_t* result = unpack_result(packedResult); | |
72 | ||
73 | LUT_ASSERT(result->nbClusters == 5); | |
74 | uint32_t medoids_ID[] = | |
75 | { | |
76 | 15*65536 + 13*256+11, | |
77 | 11, | |
78 | 17*16777216 + 0*65536 + 14*256 + 42, | |
79 | 123*65536 + 0*256 + 7, | |
80 | 51*16777216 + 0*65536 + 0*256 + 10 | |
81 | }; | |
82 | uint32_t medoids_ranks[] = | |
83 | { | |
84 | 5*65536 + 32, | |
85 | 11*256 + 4, | |
86 | 23*16777216 + 42, | |
87 | 35*65536 + 5*256 + 77, | |
88 | 1*16777216 + 1*65536 + 1*256 + 10 | |
89 | }; | |
90 | for (uint32_t i=0; i<result->nbClusters; i++) | |
91 | { | |
92 | LUT_ASSERT(result->medoids_ID[i] == medoids_ID[i]); | |
93 | LUT_ASSERT(result->medoids_ranks[i] == medoids_ranks[i]); | |
94 | } | |
95 | ||
96 | free_result(result); | |
97 | } |