|
1 | 1 | import test from "flug";
|
| 2 | +import { serve } from "srvd"; |
| 3 | +import get from '../get'; |
2 | 4 | import load from '../load';
|
| 5 | +import parse from '../parse'; |
3 | 6 | import bandArithmetic from './band-arithmetic.module';
|
4 | 7 |
|
| 8 | +// url is cached so only need 1 request |
| 9 | +serve({ debug: true, max: 1, port: 3000 }); |
| 10 | + |
5 | 11 | const url = 'http://localhost:3000/data/rgb/wildfires.tiff';
|
6 | 12 |
|
7 | 13 | const calculation1 = 'a + b';
|
@@ -43,73 +49,153 @@ function expectNoNaNValues ({ georaster, eq }) {
|
43 | 49 | });
|
44 | 50 | });
|
45 | 51 | }
|
46 |
| -// left the time measuring code commented out in the tests to make |
47 |
| -// it easier to return and further optimize the code |
48 | 52 |
|
49 |
| -test('Band Arithmetic: Run Calculation 1', async function ({ eq }) { |
| 53 | + |
| 54 | +test('(Legacy) Band Arithmetic: Run Calculation 1', async function ({ eq }) { |
50 | 55 | const georaster = await load(url);
|
51 | 56 | const computedGeoraster = await bandArithmetic(georaster, calculation1);
|
52 | 57 | const value = computedGeoraster.values[0][0][0];
|
53 |
| - const a = georaster.values[0][0][0]; |
54 |
| - const b = georaster.values[1][0][0]; |
| 58 | + const originalValues = await get(georaster); |
| 59 | + const a = originalValues[0][0][0]; |
| 60 | + const b = originalValues[1][0][0]; |
55 | 61 | eq(value, getExpectedValue1(a, b));
|
56 | 62 | expectNoInfinityValues({ georaster: computedGeoraster, eq });
|
57 | 63 | });
|
58 | 64 |
|
59 |
| -test('Band Arithmetic: Run Calculation 2', async ({ eq }) => { |
| 65 | +test('(Legacy) Band Arithmetic: Run Calculation 2', async ({ eq }) => { |
60 | 66 | const georaster = await load(url);
|
61 | 67 | const computedGeoraster = await bandArithmetic(georaster, calculation2);
|
62 | 68 | const value = computedGeoraster.values[0][0][0];
|
63 |
| - const a = georaster.values[0][0][0]; |
64 |
| - const b = georaster.values[1][0][0]; |
| 69 | + const originalValues = await get(georaster); |
| 70 | + const a = originalValues[0][0][0]; |
| 71 | + const b = originalValues[1][0][0]; |
65 | 72 | eq(value, getExpectedValue2(a, b));
|
66 | 73 | expectNoInfinityValues({ georaster: computedGeoraster, eq });
|
67 | 74 | });
|
68 | 75 |
|
69 |
| -test('Band Arithmetic: Run Calculation 3', async ({ eq }) => { |
| 76 | +test('(Legacy) Band Arithmetic: Run Calculation 3', async ({ eq }) => { |
70 | 77 | const georaster = await load(url);
|
71 | 78 | const computedGeoraster = await bandArithmetic(georaster, calculation3);
|
72 | 79 | const value = computedGeoraster.values[0][0][0];
|
73 |
| - const a = georaster.values[0][0][0]; |
74 |
| - const c = georaster.values[2][0][0]; |
| 80 | + const originalValues = await get(georaster); |
| 81 | + const a = originalValues[0][0][0]; |
| 82 | + const c = originalValues[2][0][0]; |
75 | 83 | eq(value, getExpectedValue3(a, c));
|
76 | 84 | expectNoInfinityValues({ georaster: computedGeoraster, eq });
|
77 | 85 | });
|
78 | 86 |
|
79 |
| -test('Band Arithmetic: Run Calculation 3', async ({ eq }) => { |
| 87 | +test('(Legacy) Band Arithmetic: Run Calculation 4', async ({ eq }) => { |
80 | 88 | const georaster = await load(url);
|
81 | 89 | const computedGeoraster = await bandArithmetic(georaster, calculation4);
|
82 | 90 | const value = computedGeoraster.values[0][0][0];
|
83 |
| - const a = georaster.values[0][0][0]; |
84 |
| - const b = georaster.values[1][0][0]; |
| 91 | + const originalValues = await get(georaster); |
| 92 | + const a = originalValues[0][0][0]; |
| 93 | + const b = originalValues[1][0][0]; |
85 | 94 | eq(value, getExpectedValue4(a, b));
|
86 | 95 | expectNoInfinityValues({ georaster: computedGeoraster, eq });
|
87 | 96 | });
|
88 | 97 |
|
89 |
| -test('Band Arithmetic: Run Calculation 3', async ({ eq }) => { |
| 98 | +test('(Legacy) Band Arithmetic: Run Calculation 5', async ({ eq }) => { |
90 | 99 | const georaster = await load(url);
|
91 | 100 | const computedGeoraster = await bandArithmetic(georaster, calculation5);
|
92 | 101 | const value = computedGeoraster.values[0][0][0];
|
93 |
| - const a = georaster.values[0][0][0]; |
94 |
| - const b = georaster.values[1][0][0]; |
95 |
| - const c = georaster.values[2][0][0]; |
| 102 | + const originalValues = await get(georaster); |
| 103 | + const a = originalValues[0][0][0]; |
| 104 | + const b = originalValues[1][0][0]; |
| 105 | + const c = originalValues[2][0][0]; |
96 | 106 | eq(value, getExpectedValue5(a, b, c));
|
97 | 107 | expectNoInfinityValues({ georaster: computedGeoraster, eq });
|
98 | 108 | });
|
99 | 109 |
|
100 |
| -test('Band Arithmetic: Run Calculation 6', async ({ eq }) => { |
| 110 | +test('(Legacy) Band Arithmetic: Run Calculation 6', async ({ eq }) => { |
101 | 111 | const georaster = await load(url);
|
102 | 112 | const computedGeoraster = await bandArithmetic(georaster, calculation6);
|
103 | 113 | const value = computedGeoraster.values[0][0][0];
|
104 |
| - const a = georaster.values[0][0][0]; |
105 |
| - const b = georaster.values[1][0][0]; |
106 |
| - const c = georaster.values[2][0][0]; |
| 114 | + const originalValues = await get(georaster); |
| 115 | + const a = originalValues[0][0][0]; |
| 116 | + const b = originalValues[1][0][0]; |
| 117 | + const c = originalValues[2][0][0]; |
107 | 118 | eq(value, getExpectedValue6(a, b, c));
|
108 | 119 | expectNoInfinityValues({ georaster: computedGeoraster, eq });
|
109 | 120 | });
|
110 | 121 |
|
111 |
| -test('Band Arithmetic: Run Calculation 7', async ({ eq }) => { |
| 122 | +test('(Legacy) Band Arithmetic: Run Calculation 7', async ({ eq }) => { |
112 | 123 | const georaster = await load(url);
|
113 | 124 | const computedGeoraster = await bandArithmetic(georaster, calculation7);
|
114 | 125 | expectNoNaNValues({ georaster: computedGeoraster, eq });
|
115 | 126 | });
|
| 127 | + |
| 128 | + |
| 129 | +// MODERN |
| 130 | +test('(Modern) Band Arithmetic: Run Calculation 1', async function ({ eq }) { |
| 131 | + const georaster = await parse(url); |
| 132 | + const computedGeoraster = await bandArithmetic(url, calculation1); |
| 133 | + const value = computedGeoraster.values[0][0][0]; |
| 134 | + const originalValues = await get(georaster); |
| 135 | + const a = originalValues[0][0][0]; |
| 136 | + const b = originalValues[1][0][0]; |
| 137 | + eq(value, getExpectedValue1(a, b)); |
| 138 | + expectNoInfinityValues({ georaster: computedGeoraster, eq }); |
| 139 | +}); |
| 140 | + |
| 141 | +test('(Modern) Band Arithmetic: Run Calculation 2', async ({ eq }) => { |
| 142 | + const georaster = await parse(url); |
| 143 | + const computedGeoraster = await bandArithmetic(url, calculation2); |
| 144 | + const value = computedGeoraster.values[0][0][0]; |
| 145 | + const originalValues = await get(georaster); |
| 146 | + const a = originalValues[0][0][0]; |
| 147 | + const b = originalValues[1][0][0]; |
| 148 | + eq(value, getExpectedValue2(a, b)); |
| 149 | + expectNoInfinityValues({ georaster: computedGeoraster, eq }); |
| 150 | +}); |
| 151 | + |
| 152 | +test('(Modern) Band Arithmetic: Run Calculation 3', async ({ eq }) => { |
| 153 | + const georaster = await parse(url); |
| 154 | + const computedGeoraster = await bandArithmetic(url, calculation3); |
| 155 | + const value = computedGeoraster.values[0][0][0]; |
| 156 | + const originalValues = await get(georaster); |
| 157 | + const a = originalValues[0][0][0]; |
| 158 | + const c = originalValues[2][0][0]; |
| 159 | + eq(value, getExpectedValue3(a, c)); |
| 160 | + expectNoInfinityValues({ georaster: computedGeoraster, eq }); |
| 161 | +}); |
| 162 | + |
| 163 | +test('(Modern) Band Arithmetic: Run Calculation 4', async ({ eq }) => { |
| 164 | + const georaster = await parse(url); |
| 165 | + const computedGeoraster = await bandArithmetic(url, calculation4); |
| 166 | + const value = computedGeoraster.values[0][0][0]; |
| 167 | + const originalValues = await get(georaster); |
| 168 | + const a = originalValues[0][0][0]; |
| 169 | + const b = originalValues[1][0][0]; |
| 170 | + eq(value, getExpectedValue4(a, b)); |
| 171 | + expectNoInfinityValues({ georaster: computedGeoraster, eq }); |
| 172 | +}); |
| 173 | + |
| 174 | +test('(Modern) Band Arithmetic: Run Calculation 5', async ({ eq }) => { |
| 175 | + const georaster = await parse(url); |
| 176 | + const computedGeoraster = await bandArithmetic(url, calculation5); |
| 177 | + const value = computedGeoraster.values[0][0][0]; |
| 178 | + const originalValues = await get(georaster); |
| 179 | + const a = originalValues[0][0][0]; |
| 180 | + const b = originalValues[1][0][0]; |
| 181 | + const c = originalValues[2][0][0]; |
| 182 | + eq(value, getExpectedValue5(a, b, c)); |
| 183 | + expectNoInfinityValues({ georaster: computedGeoraster, eq }); |
| 184 | +}); |
| 185 | + |
| 186 | +test('(Modern) Band Arithmetic: Run Calculation 6', async ({ eq }) => { |
| 187 | + const georaster = await parse(url); |
| 188 | + const computedGeoraster = await bandArithmetic(url, calculation6); |
| 189 | + const value = computedGeoraster.values[0][0][0]; |
| 190 | + const originalValues = await get(georaster); |
| 191 | + const a = originalValues[0][0][0]; |
| 192 | + const b = originalValues[1][0][0]; |
| 193 | + const c = originalValues[2][0][0]; |
| 194 | + eq(value, getExpectedValue6(a, b, c)); |
| 195 | + expectNoInfinityValues({ georaster: computedGeoraster, eq }); |
| 196 | +}); |
| 197 | + |
| 198 | +test('(Modern) Band Arithmetic: Run Calculation 7', async ({ eq }) => { |
| 199 | + const computedGeoraster = await bandArithmetic(url, calculation7); |
| 200 | + expectNoNaNValues({ georaster: computedGeoraster, eq }); |
| 201 | +}); |
0 commit comments