Skip to content
Snippets Groups Projects
Commit 60c55ea2 authored by Millian Poquet's avatar Millian Poquet
Browse files

c++ unit tests (gtest)

parent 9e4c9f80
Branches
Tags
No related merge requests found
......@@ -56,6 +56,7 @@ let self = rec {
pkg-config
ninja
zeromq
gtest.dev
];
};
client-cpp = pkgs.stdenv.mkDerivation {
......
......@@ -24,3 +24,19 @@ simulator = executable('simulator', [
dependencies: deps,
install: true
)
# unit tests with gtest
if get_option('do_unit_tests')
gtest_dep = dependency('gtest_main', version: '>=1.8.0', required: true)
test_incdir = include_directories('test', 'src')
test_src = [
'test/flop_conversion.cpp',
'src/compute.cpp', 'src/compute.hpp'
]
unittest = executable('simulator-unit-tester',
test_src,
dependencies: [gtest_dep],
include_directories: [test_incdir]
)
test('unittest', unittest)
endif
option('do_unit_tests', type : 'boolean', value : false,
description : 'Enable unit tests (requires gtest)')
#include <gtest/gtest.h>
#include "compute.hpp"
void test_wrapper_flop_conversion(float desired, float actual)
{
float got = desired_flops_to_simulated_flops(desired);
EXPECT_FLOAT_EQ(got, actual);
}
TEST(flop_conversion, small)
{
test_wrapper_flop_conversion(1.0f, 1.0f);
test_wrapper_flop_conversion(5.0f, 5.0f);
test_wrapper_flop_conversion(10.0f, 10.0f);
test_wrapper_flop_conversion(100.0f, 100.0f);
}
TEST(flop_conversion, big)
{
test_wrapper_flop_conversion(1e6, 1e6);
test_wrapper_flop_conversion(1e9, 1e9);
test_wrapper_flop_conversion(1e18, 1e18);
}
TEST(flop_conversion, wrong)
{
test_wrapper_flop_conversion(1e26, 1e27);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment