Commit 890dfec9 authored by Ludovic Courtès's avatar Ludovic Courtès

data: Add test for 'load' and 'save', and run it.

parent 46f6c305
# Original NIST data and information can be found here:
#DIM 1 1
#VS 0
9.65E0 0.0082E0
10.74E0 0.0112E0
11.81E0 0.0149E0
12.88E0 0.0198E0
14.06E0 0.0248E0
15.28E0 0.0324E0
16.63E0 0.0420E0
18.19E0 0.0549E0
19.88E0 0.0719E0
21.84E0 0.0963E0
24.00E0 0.1291E0
26.25E0 0.1710E0
28.86E0 0.2314E0
31.85E0 0.3227E0
35.79E0 0.4809E0
40.18E0 0.7084E0
44.74E0 1.0220E0
49.53E0 1.4580E0
53.94E0 1.9520E0
58.29E0 2.5410E0
62.63E0 3.2230E0
67.03E0 3.9990E0
71.25E0 4.8520E0
75.22E0 5.7320E0
79.33E0 6.7270E0
83.56E0 7.8350E0
87.75E0 9.0250E0
91.93E0 10.2670E0
96.10E0 11.5780E0
100.28E0 12.9440E0
104.46E0 14.3770E0
108.66E0 15.8560E0
112.71E0 17.3310E0
116.88E0 18.8850E0
121.33E0 20.5750E0
125.79E0 22.3200E0
125.79E0 22.3030E0
128.74E0 23.4600E0
130.27E0 24.0600E0
133.33E0 25.2720E0
134.79E0 25.8530E0
137.93E0 27.1100E0
139.33E0 27.6580E0
142.46E0 28.9240E0
143.90E0 29.5110E0
146.91E0 30.7100E0
148.51E0 31.3500E0
151.41E0 32.5200E0
153.17E0 33.2300E0
155.97E0 34.3300E0
157.76E0 35.0600E0
160.56E0 36.1700E0
162.30E0 36.8400E0
165.21E0 38.0100E0
166.90E0 38.6700E0
169.92E0 39.8700E0
170.32E0 40.0300E0
171.54E0 40.5000E0
173.79E0 41.3700E0
174.57E0 41.6700E0
176.25E0 42.3100E0
177.34E0 42.7300E0
179.19E0 43.4600E0
181.02E0 44.1400E0
182.08E0 44.5500E0
183.88E0 45.2200E0
185.75E0 45.9200E0
186.80E0 46.3000E0
188.63E0 47.0000E0
190.45E0 47.6800E0
191.48E0 48.0600E0
193.35E0 48.7400E0
195.22E0 49.4100E0
196.23E0 49.7600E0
198.05E0 50.4300E0
199.97E0 51.1100E0
201.06E0 51.5000E0
202.83E0 52.1200E0
204.69E0 52.7600E0
205.86E0 53.1800E0
207.58E0 53.7800E0
209.50E0 54.4600E0
210.65E0 54.8300E0
212.33E0 55.4000E0
215.43E0 56.4300E0
217.16E0 57.0300E0
220.21E0 58.0000E0
221.98E0 58.6100E0
225.06E0 59.5800E0
226.79E0 60.1100E0
229.92E0 61.1000E0
231.69E0 61.6500E0
234.77E0 62.5900E0
236.60E0 63.1200E0
239.63E0 64.0300E0
241.50E0 64.6200E0
244.48E0 65.4900E0
246.40E0 66.0300E0
249.35E0 66.8900E0
251.32E0 67.4200E0
254.22E0 68.2300E0
256.24E0 68.7700E0
259.11E0 69.5900E0
261.18E0 70.1100E0
264.02E0 70.8600E0
266.13E0 71.4300E0
268.94E0 72.1600E0
271.09E0 72.7000E0
273.87E0 73.4000E0
276.08E0 73.9300E0
278.83E0 74.6000E0
281.08E0 75.1600E0
283.81E0 75.8200E0
286.11E0 76.3400E0
288.81E0 76.9800E0
291.08E0 77.4800E0
293.75E0 78.0800E0
295.99E0 78.6000E0
298.64E0 79.1700E0
300.84E0 79.6200E0
302.02E0 79.8800E0
303.48E0 80.1900E0
305.65E0 80.6600E0
308.27E0 81.2200E0
310.41E0 81.6600E0
313.01E0 82.1600E0
315.12E0 82.5900E0
317.71E0 83.1400E0
319.79E0 83.5000E0
322.36E0 84.0000E0
324.42E0 84.4000E0
326.98E0 84.8900E0
329.01E0 85.2600E0
331.56E0 85.7400E0
333.56E0 86.0700E0
336.10E0 86.5400E0
338.08E0 86.8900E0
340.60E0 87.3200E0
342.57E0 87.6500E0
345.08E0 88.1000E0
347.02E0 88.4300E0
349.52E0 88.8300E0
351.44E0 89.1200E0
353.93E0 89.5400E0
355.83E0 89.8500E0
358.32E0 90.2500E0
360.20E0 90.5500E0
362.67E0 90.9300E0
364.53E0 91.2000E0
367.00E0 91.5500E0
371.30E0 92.2000E0
import os
Import('env', 'ALTA_LIBS')
env = env.Clone()
......@@ -6,3 +8,23 @@ env.AppendUnique(LIBS = ALTA_LIBS)
env.Alias('tests', env.Program('./build/half-test-1', './params/half-test-1.cpp'))
env.Alias('tests', env.Program('./build/half-test-2', './params/half-test-2.cpp'))
env.Alias('tests', env.Program('./build/data-io-test', 'data-io.cpp'))
# Data files used by the tests.
test_file = File('Kirby2.dat').srcnode().abspath
test_data_directory = os.path.dirname(test_file)
# Inspired by <>.
def run_unit_test(env, target, source):
program = str(source[0].abspath)
envvars = os.environ
envvars['TEST_DATA_DIRECTORY'] = test_data_directory
if os.spawnle(os.P_WAIT, program, program, envvars) == 0:
return 1
env.Alias('tests', env.Command("test.passed", 'build/data-io-test',
/* ALTA --- Analysis of Bidirectional Reflectance Distribution Functions
Copyright (C) 2015 Inria
This file is part of ALTA.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at */
/* Test whether the 'load' and 'save' methods of 'data' work as expected. We
* do that by bitwise comparison of the files produced by 'save', which is
* not ideal (we may want to compare the in-memory representations
* instead.) */
#include <core/args.h>
#include <core/data.h>
#include <core/vertical_segment.h>
#include <string>
#include <iostream>
#include <cstring>
#include <cstdlib>
static const std::string data_file = "Kirby2.dat";
static void make_temp_file_name(std::string &result)
static std::string suffix;
result = "t-data-io" + suffix;
suffix += "-";
// Try hard to read N bytes from INPUT into BUF.
static std::streamsize read_exactly(std::istream &input, char *buf, std::streamsize n)
std::streamsize total;
for (total = 0;
total < n && !input.eof();
total += input.gcount())
{[total], n - total);
return total;
// Return true if the contents of FILE1 are identical to the contents of
// FILE2.
static bool files_are_equal(const std::string &file1, const std::string &file2)
std::ifstream i1, i2;
while (!i1.eof() && !i2.eof())
char buf1[16384], buf2[16384];
std::streamsize len1 = read_exactly(i1, buf1, sizeof buf1);
std::streamsize len2 = read_exactly(i2, buf2, sizeof buf2);
if (len1 != len2 || memcmp(buf1, buf2, len1) != 0) {
return false;
return i1.eof() && (i1.eof() == i2.eof());
int main(int argc, char** argv)
std::string temp_file1, temp_file2;
vertical_segment sample1, sample2;
std::string data_dir = getenv("TEST_DATA_DIRECTORY") ?: ".";
std::string input_file = data_dir + "/" + data_file;
// Use the standard load/save methods.
return files_are_equal(temp_file1, temp_file2)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment