Functions
canonical_number_test.cc File Reference
#include "catch2/catch.hpp"
#include "cetlib/canonical_number.h"
#include <string>

Go to the source code of this file.

Functions

 TEST_CASE ("Conversion of string representations of numbers to canonical ""representations.")
 

Function Documentation

TEST_CASE ( "Conversion of string representations of numbers to canonical ""representations."  )

Definition at line 18 of file canonical_number_test.cc.

20 {
21  CHECK(becomes("0", "0"));
22  CHECK(becomes("+0", "0"));
23  CHECK(becomes("-0", "0"));
24  CHECK(becomes("000", "0"));
25  CHECK(becomes("+000", "0"));
26  CHECK(becomes("-000", "0"));
27  CHECK(becomes("0.0", "0"));
28  CHECK(becomes("+0.0", "0"));
29  CHECK(becomes("-0.0e-5", "0"));
30 
31  CHECK(becomes("123456", "123456"));
32  CHECK(becomes("12345678", "1.2345678e7"));
33  CHECK(!becomes("", ""));
34  CHECK(becomes(".12", "1.2e-1"));
35  CHECK(becomes("12E4", "120000"));
36  CHECK(becomes("12E5", "1.2e6"));
37  CHECK(becomes("12.000E5", "1.2e6"));
38  CHECK(becomes("12E-4", "1.2e-3"));
39  CHECK(becomes("0.09", "9e-2"));
40 
41  CHECK(becomes("-0.0e-0", "0"));
42  CHECK(becomes("+0.0E0", "0"));
43  CHECK(becomes("-0e99", "0"));
44  CHECK(becomes("-.00", "0"));
45 
46  CHECK(!becomes("1.2.3", ""));
47  CHECK(!becomes("1.2, 3", ""));
48  CHECK(!becomes("1.2X3", ""));
49  CHECK(!becomes("0x123abx", ""));
50  CHECK(!becomes("+0x123ab", ""));
51  CHECK(!becomes("0x", ""));
52  CHECK(!becomes("0b123", ""));
53  CHECK(!becomes("+0b101", ""));
54  CHECK(!becomes("0b", ""));
55 
56  CHECK(becomes("0X000", "0"));
57  CHECK(becomes("0x123ab", "74667"));
58  CHECK(becomes("0x123DE", "74718"));
59  CHECK(becomes("0X123ab", "74667"));
60  CHECK(becomes("0X00123De", "74718"));
61  CHECK(becomes("0x1234567890", "7.818749352e10"));
62 
63  CHECK(becomes("0b000", "0"));
64  CHECK(becomes("0b101", "5"));
65  CHECK(becomes("0b01101", "13"));
66  CHECK(becomes("0b1000110100101100011001", "2.312985e6"));
67 }
void becomes(std::string const &input, std::string const &wanted)