MCPcopy Create free account
hub / github.com/boostorg/compute / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

test/test_literal_conversion.cpp:20–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18#include <boost/compute/detail/literal.hpp>
19
20BOOST_AUTO_TEST_CASE(literal_conversion_float)
21{
22 std::vector<float> values, roundtrip;
23 values.push_back(1.2345679f);
24 values.push_back(1.2345680f);
25 values.push_back(1.2345681f);
26 for (size_t i = 0; i < values.size(); i++) {
27 std::string literal = boost::compute::detail::make_literal(values[i]);
28 // Check that we got something in the literal, and that at least the first
29 // 6 characters (5 digits) look good
30 BOOST_CHECK_EQUAL(literal.substr(0, 6), "1.2345");
31
32 // libc++ stream extraction fails on a value such as "1.2f" rather than extracting 1.2
33 // and leaving the f; so check the "f", then slice it off for the extraction below:
34 BOOST_CHECK_EQUAL(literal.substr(literal.length()-1), "f");
35
36 std::istringstream iss(literal.substr(0, literal.length()-1));
37 float x;
38 iss >> x;
39 roundtrip.push_back(x);
40 }
41 BOOST_CHECK_EQUAL(values[0], roundtrip[0]);
42 BOOST_CHECK_EQUAL(values[1], roundtrip[1]);
43 BOOST_CHECK_EQUAL(values[2], roundtrip[2]);
44}
45
46BOOST_AUTO_TEST_CASE(literal_conversion_double)
47{

Callers

nothing calls this directly

Calls 5

make_literalFunction · 0.85
push_backMethod · 0.80
substrMethod · 0.80
lengthMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected