8 #include <catch2/catch_test_macros.hpp>
13 using namespace nmodl;
14 using namespace visitor;
19 SCENARIO(
"C codegen utility functions",
"[codegen][util][c]") {
20 GIVEN(
"Double constant as string") {
21 std::string double_constant =
"0.012345678901234567";
23 THEN(
"Codegen C Visitor prints double with same precision") {
25 REQUIRE(nmodl_constant_result == double_constant);
29 GIVEN(
"Integer constant as string") {
30 std::string double_constant =
"1";
32 std::string codegen_output =
"1.0";
34 THEN(
"Codegen C Visitor prints integer as double number") {
36 REQUIRE(nmodl_constant_result == codegen_output);
40 GIVEN(
"Double constants in scientific notation as strings") {
41 input_result_map tests({{
"1e+18",
"1e+18"}, {
"1e-18",
"1e-18"}, {
"1E18",
"1E18"}});
43 THEN(
"Codegen C Visitor prints doubles with scientific notation") {
44 for (
const auto& test: tests) {
50 GIVEN(
"Float constant as string") {
51 std::string float_constant =
"0.01234567";
53 THEN(
"Codegen C Visitor prints float with same precision") {
55 REQUIRE(nmodl_constant_result == float_constant);
59 GIVEN(
"Float constant as string") {
60 std::string float_constant =
"1";
62 std::string codegen_output =
"1.0";
64 THEN(
"Codegen C Visitor prints integer as double number") {
66 REQUIRE(nmodl_constant_result == codegen_output);
70 GIVEN(
"Float constants in scientific notation as strings") {
71 input_result_map tests({{
"1e+18",
"1e+18"}, {
"1e-18",
"1e-18"}, {
"1E18",
"1E18"}});
73 THEN(
"Codegen C Visitor prints doubles with scientific notation") {
74 for (
const auto& test: tests) {
Visitor for printing C++ code compatible with legacy api of CoreNEURON
Implement utility functions for codegen visitors.
std::string format_float_string(const std::string &s_value)
Handles the float constants format being printed in the generated code.
std::string format_double_string(const std::string &s_value)
Handles the double constants format being printed in the generated code.
encapsulates code generation backend implementations
std::unordered_map< std::string, std::string > input_result_map
SCENARIO("C codegen utility functions", "[codegen][util][c]")