Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions lib/utils/test/src/utils/containers/concat_vectors.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "utils/containers/concat_vectors.h"
#include "test/utils/doctest/fmt/vector.h"
#include <doctest/doctest.h>
#include <vector>

using namespace ::FlexFlow;

TEST_SUITE(FF_TEST_SUITE) {
TEST_CASE("concat_vectors") {
SUBCASE("two vectors") {
std::vector<int> prefix = {1, 2};
std::vector<int> postfix = {3, 4};

std::vector<int> result = concat_vectors(prefix, postfix);
std::vector<int> correct = {1, 2, 3, 4};

CHECK(result == correct);
}

SUBCASE("vector of vectors") {
std::vector<std::vector<int>> vecs = {{1, 2}, {3}, {4, 5}};

std::vector<int> result = concat_vectors(vecs);
std::vector<int> correct = {1, 2, 3, 4, 5};

CHECK(result == correct);
}

SUBCASE("empty vector of vectors") {
std::vector<std::vector<int>> vecs = {};

std::vector<int> result = concat_vectors(vecs);
std::vector<int> correct = {};

CHECK(result == correct);
}
}
}
30 changes: 30 additions & 0 deletions lib/utils/test/src/utils/containers/extend_vector.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "utils/containers/extend_vector.h"
#include "test/utils/doctest/fmt/vector.h"
#include <doctest/doctest.h>
#include <vector>

using namespace ::FlexFlow;
// checks rhs gets added to the end of lhs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is sufficiently clear, so we can remove this comment. Make sure to add a blank line here.

TEST_SUITE(FF_TEST_SUITE) {
TEST_CASE("extend_vector") {
SUBCASE("non-empty vectors") {
std::vector<int> lhs = {1, 2};
std::vector<int> rhs = {3, 4};

extend_vector(lhs, rhs);
std::vector<int> correct = {1, 2, 3, 4};

CHECK(lhs == correct);
}
// checks that lhs stays the same when the rhs is empty

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also remove this comment and add a blank line.

SUBCASE("empty rhs") {
std::vector<int> lhs = {1, 2};
std::vector<int> rhs = {};

extend_vector(lhs, rhs);
std::vector<int> correct = {1, 2};

CHECK(lhs == correct);
}
}
}
31 changes: 31 additions & 0 deletions lib/utils/test/src/utils/containers/generate_vector.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "utils/containers/generate_vector.h"
#include "test/utils/doctest/fmt/vector.h"
#include "utils/exception.h"
#include "utils/nonnegative_int/nonnegative_int.h"
#include <doctest/doctest.h>
#include <vector>

using namespace ::FlexFlow;

TEST_SUITE(FF_TEST_SUITE) {
TEST_CASE("generate_vector") {
SUBCASE("empty vector") {
std::vector<int> result = generate_vector(0_n, [](nonnegative_int) -> int {
PANIC("lambda should not be called");
});
std::vector<int> correct = {};

CHECK(result == correct);
}
SUBCASE("non-empty vector") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a blank line before this one.

std::vector<int> result = generate_vector(5_n, [](nonnegative_int idx) {
int i = idx.unwrap_nonnegative();
return i * i;

});
std::vector<int> correct = {0, 1, 4, 9, 16};

CHECK(result == correct);
}
}
}