From c0217184f54cf05a103b0fc651f8cc8a1ffc387d Mon Sep 17 00:00:00 2001 From: Tomerkm Date: Fri, 2 Jun 2023 19:42:00 +0300 Subject: [PATCH 01/10] Added to the file unit-algorithm.cpp (c++ 11) the following functions that were missing: 1. iota 2. copy 3. copy if 4. copy n --- tests/src/unit-algorithms.cpp | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index f4b87f8fa3..125673b620 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -294,4 +294,70 @@ TEST_CASE("algorithms") std::sort_heap(j_array.begin(), j_array.end()); CHECK(j_array == json({false, true, 3, 13, 29, {{"one", 1}, {"two", 2}}, {1, 2, 3}, "baz", "foo"})); } + + SECTION("iota") + { + SECTION("int") + { + std::vector arr(10); + json json_arr(arr); + std::iota(json_arr.begin(), json_arr.end(), 0); + CHECK(json_arr == json({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); + } + + SECTION("double") + { + std::vector arr(10); + json json_arr(arr); + std::iota(json_arr.begin(), json_arr.end(), 0.5); + CHECK(json_arr == json({0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5})); + } + + SECTION("char") + { + std::vector arr(10); + json json_arr(arr); + std::iota(json_arr.begin(), json_arr.end(), '0'); + CHECK(json_arr == json({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'})); + } + } + + SECTION("copy") + { + SECTION("copy without if") + { + json dest_arr; + json source_arr = {1, 2, 3, 4}; + + std::copy(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr)); + + CHECK(dest_arr == source_arr); + } + SECTION("copy if") + { + json dest_arr; + json source_arr = {0,3,6,9,12,15,20}; + auto condition = [](int x) { + return x % 3 == 0; + }; + + std::copy_if(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr), condition); + CHECK(dest_arr == json({0, 3, 6, 9, 12, 15})); + } + SECTION("copy n") + { + json source_arr = {'1', '2', '3', '4', '5', '6', '7'}; + json dest_arr; + const unsigned char numToCopy = 2; + + std::copy_n(source_arr.begin(), numToCopy, std::back_inserter(dest_arr)); + CHECK(dest_arr == json{'1','2'}); + + } + + } + + + + } From 741e606bc6ddbcfdcdebf993642e8c2c8cebd65d Mon Sep 17 00:00:00 2001 From: Tomerkm Date: Fri, 2 Jun 2023 20:46:16 +0300 Subject: [PATCH 02/10] fixed error compile linux --- tests/src/unit-algorithms.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index 125673b620..cf379d8186 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -299,7 +299,7 @@ TEST_CASE("algorithms") { SECTION("int") { - std::vector arr(10); + const std::vector arr(10); json json_arr(arr); std::iota(json_arr.begin(), json_arr.end(), 0); CHECK(json_arr == json({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); @@ -307,7 +307,7 @@ TEST_CASE("algorithms") SECTION("double") { - std::vector arr(10); + const std::vector arr(10); json json_arr(arr); std::iota(json_arr.begin(), json_arr.end(), 0.5); CHECK(json_arr == json({0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5})); @@ -315,7 +315,7 @@ TEST_CASE("algorithms") SECTION("char") { - std::vector arr(10); + const std::vector arr(10); json json_arr(arr); std::iota(json_arr.begin(), json_arr.end(), '0'); CHECK(json_arr == json({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'})); @@ -327,7 +327,7 @@ TEST_CASE("algorithms") SECTION("copy without if") { json dest_arr; - json source_arr = {1, 2, 3, 4}; + const json source_arr = {1, 2, 3, 4}; std::copy(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr)); @@ -336,17 +336,17 @@ TEST_CASE("algorithms") SECTION("copy if") { json dest_arr; - json source_arr = {0,3,6,9,12,15,20}; - auto condition = [](int x) { - return x % 3 == 0; - }; - - std::copy_if(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr), condition); + const json source_arr = {0,3,6,9,12,15,20}; + + + std::copy_if(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr), [](const json& _value) { + return _value.get() % 3 == 0; + }); CHECK(dest_arr == json({0, 3, 6, 9, 12, 15})); } SECTION("copy n") { - json source_arr = {'1', '2', '3', '4', '5', '6', '7'}; + const json source_arr = {'1', '2', '3', '4', '5', '6', '7'}; json dest_arr; const unsigned char numToCopy = 2; From 01e313e3f5546bf88e1f4afb43d16a5d6a1db026 Mon Sep 17 00:00:00 2001 From: Tomerkm Date: Sat, 3 Jun 2023 10:48:05 +0300 Subject: [PATCH 03/10] removed the test failed in gcc --- tests/src/unit-algorithms.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index cf379d8186..e444f57641 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -313,13 +313,6 @@ TEST_CASE("algorithms") CHECK(json_arr == json({0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5})); } - SECTION("char") - { - const std::vector arr(10); - json json_arr(arr); - std::iota(json_arr.begin(), json_arr.end(), '0'); - CHECK(json_arr == json({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'})); - } } SECTION("copy") @@ -346,12 +339,12 @@ TEST_CASE("algorithms") } SECTION("copy n") { - const json source_arr = {'1', '2', '3', '4', '5', '6', '7'}; + const json source_arr = {0, 1, 2, 3, 4, 5, 6, 7}; json dest_arr; const unsigned char numToCopy = 2; std::copy_n(source_arr.begin(), numToCopy, std::back_inserter(dest_arr)); - CHECK(dest_arr == json{'1','2'}); + CHECK(dest_arr == json{0, 1}); } From ccce0b1a8b9af2fa3d90e42d922d3d4a0d301650 Mon Sep 17 00:00:00 2001 From: Tomerkm Date: Sat, 3 Jun 2023 12:31:52 +0300 Subject: [PATCH 04/10] comment copy function to check if CI will be passed --- tests/src/unit-algorithms.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index e444f57641..63c9dc4692 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -315,6 +315,7 @@ TEST_CASE("algorithms") } + /* SECTION("copy") { SECTION("copy without if") @@ -349,7 +350,7 @@ TEST_CASE("algorithms") } } - + */ From 9c7247f4b0ad76997fd75384da712eb3cab4e368 Mon Sep 17 00:00:00 2001 From: Tomerkm Date: Sat, 3 Jun 2023 12:46:55 +0300 Subject: [PATCH 05/10] removed vector std --- tests/src/unit-algorithms.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index 63c9dc4692..29b5ad23b4 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -299,16 +299,14 @@ TEST_CASE("algorithms") { SECTION("int") { - const std::vector arr(10); - json json_arr(arr); + json json_arr = {0, 5, 2, 4, 10, 20, 30, 40, 50, 1}; std::iota(json_arr.begin(), json_arr.end(), 0); CHECK(json_arr == json({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); } SECTION("double") { - const std::vector arr(10); - json json_arr(arr); + json json_arr = {0.5, 51, 2.53, 4.1, 10.43, 20.12, 30.5, 140, 50.50, 1}; std::iota(json_arr.begin(), json_arr.end(), 0.5); CHECK(json_arr == json({0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5})); } From b4fd9e5545dcbf49526e4e3cf023e8710c79e2c7 Mon Sep 17 00:00:00 2001 From: Tomerkm Date: Sat, 3 Jun 2023 12:49:47 +0300 Subject: [PATCH 06/10] move up --- tests/src/unit-algorithms.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index 29b5ad23b4..33e1397300 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -310,7 +310,6 @@ TEST_CASE("algorithms") std::iota(json_arr.begin(), json_arr.end(), 0.5); CHECK(json_arr == json({0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5})); } - } /* From b4312a18de3342dad24f1b46a90c6a90bbf53f1c Mon Sep 17 00:00:00 2001 From: Tomerkm Date: Sat, 3 Jun 2023 14:07:38 +0300 Subject: [PATCH 07/10] removed float check --- tests/src/unit-algorithms.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index 33e1397300..af95bc10ac 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -300,16 +300,10 @@ TEST_CASE("algorithms") SECTION("int") { json json_arr = {0, 5, 2, 4, 10, 20, 30, 40, 50, 1}; - std::iota(json_arr.begin(), json_arr.end(), 0); + const int number = 0; + std::iota(json_arr.begin(), json_arr.end(), number); CHECK(json_arr == json({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); } - - SECTION("double") - { - json json_arr = {0.5, 51, 2.53, 4.1, 10.43, 20.12, 30.5, 140, 50.50, 1}; - std::iota(json_arr.begin(), json_arr.end(), 0.5); - CHECK(json_arr == json({0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5})); - } } /* From e3b114ecab8e156928d0f29db4b72903981d91c7 Mon Sep 17 00:00:00 2001 From: Tomerkm Date: Sat, 10 Jun 2023 12:50:24 +0300 Subject: [PATCH 08/10] formated the file using tests/src/unit-algorithms.cpp make amalgamat --- tests/src/unit-algorithms.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index af95bc10ac..be5789bba6 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -322,12 +322,12 @@ TEST_CASE("algorithms") { json dest_arr; const json source_arr = {0,3,6,9,12,15,20}; - - + + std::copy_if(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr), [](const json& _value) { return _value.get() % 3 == 0; }); - CHECK(dest_arr == json({0, 3, 6, 9, 12, 15})); + CHECK(dest_arr == json({0, 3, 6, 9, 12, 15})); } SECTION("copy n") { @@ -336,10 +336,10 @@ TEST_CASE("algorithms") const unsigned char numToCopy = 2; std::copy_n(source_arr.begin(), numToCopy, std::back_inserter(dest_arr)); - CHECK(dest_arr == json{0, 1}); + CHECK(dest_arr == json{0, 1}); } - + } */ From 6706a8919c3eccefa48d2c03fe28c9d08375c1c8 Mon Sep 17 00:00:00 2001 From: Tomerkm Date: Sat, 10 Jun 2023 15:35:49 +0300 Subject: [PATCH 09/10] canceled comments --- tests/src/unit-algorithms.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index be5789bba6..c7aa030fde 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -306,7 +306,7 @@ TEST_CASE("algorithms") } } - /* + SECTION("copy") { SECTION("copy without if") @@ -321,12 +321,13 @@ TEST_CASE("algorithms") SECTION("copy if") { json dest_arr; - const json source_arr = {0,3,6,9,12,15,20}; + const json source_arr = {0, 3, 6, 9, 12, 15, 20}; - std::copy_if(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr), [](const json& _value) { + std::copy_if(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr), [](const json & _value) + { return _value.get() % 3 == 0; - }); + }); CHECK(dest_arr == json({0, 3, 6, 9, 12, 15})); } SECTION("copy n") @@ -341,7 +342,6 @@ TEST_CASE("algorithms") } } - */ From ae144bae3a87a2f5ebbf99719eae7979eebb192e Mon Sep 17 00:00:00 2001 From: Tomerkm Date: Sat, 10 Jun 2023 23:10:56 +0300 Subject: [PATCH 10/10] added the tests that was before editing --- tests/src/unit-algorithms.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/src/unit-algorithms.cpp b/tests/src/unit-algorithms.cpp index c7aa030fde..a4fd747d87 100644 --- a/tests/src/unit-algorithms.cpp +++ b/tests/src/unit-algorithms.cpp @@ -300,10 +300,22 @@ TEST_CASE("algorithms") SECTION("int") { json json_arr = {0, 5, 2, 4, 10, 20, 30, 40, 50, 1}; - const int number = 0; - std::iota(json_arr.begin(), json_arr.end(), number); + std::iota(json_arr.begin(), json_arr.end(), 0); CHECK(json_arr == json({0, 1, 2, 3, 4, 5, 6, 7, 8, 9})); } + SECTION("double") + { + json json_arr = {0.5, 1.5, 1.3, 4.1, 10.2, 20.5, 30.6, 40.1, 50.22, 1.5}; + std::iota(json_arr.begin(), json_arr.end(), 0.5); + CHECK(json_arr == json({0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5})); + } + + SECTION("char") + { + json json_arr = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', '0', '1'}; + std::iota(json_arr.begin(), json_arr.end(), '0'); + CHECK(json_arr == json({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'})); + } } @@ -340,7 +352,15 @@ TEST_CASE("algorithms") CHECK(dest_arr == json{0, 1}); } + SECTION("copy n chars") + { + const json source_arr = {'1', '2', '3', '4', '5', '6', '7'}; + json dest_arr; + const unsigned char numToCopy = 4; + std::copy_n(source_arr.begin(), numToCopy, std::back_inserter(dest_arr)); + CHECK(dest_arr == json{'1', '2', '3', '4'}); + } }