Skip to content

Commit

Permalink
Use doctest and add combination var checks
Browse files Browse the repository at this point in the history
  • Loading branch information
markkohdev committed Jul 1, 2024
1 parent 321805d commit 6b725fb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
3 changes: 1 addition & 2 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
add_executable(test test_main.cpp)

add_executable(test doctest_setup.cpp test_main.cpp)

target_link_libraries(test
PUBLIC
Expand Down
2 changes: 2 additions & 0 deletions cpp/test/doctest_setup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
54 changes: 38 additions & 16 deletions cpp/test/test_main.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"

#include "TypedIndex.h"
#include <tuple>
#include <type_traits>

#include "doctest.h"
template <typename dist_t, typename data_t = dist_t, typename scalefactor = std::ratio<1, 1>>
void testCombination(TypedIndex<dist_t, data_t, scalefactor> &index, SpaceType spaceType, int numDimensions,
StorageDataType storageType) {
CHECK(toString(index.getSpace()) == toString(spaceType));
CHECK(index.getNumDimensions() == numDimensions);
CHECK(toString(index.getStorageDataType()) == toString(storageType));
}

TEST_CASE("Test combinations of different instantiations and sizes") {
std::vector<SpaceType> spaceTypesSet = {SpaceType::Euclidean, SpaceType::InnerProduct};
std::vector<int> numDimensionsSet = {4, 16, 128, 1024};
std::vector<int> numElementsSet = {100, 1000, 100000};
std::vector<StorageDataType> storageTypesSet = {StorageDataType::Float8, StorageDataType::Float32,
StorageDataType::E4M3};

TEST_CASE("Basic Init") {
for (auto spaceType : spaceTypesSet) {
for (auto numDimensions : numDimensionsSet) {
for (auto numElements : numElementsSet) {
for (auto storageType : storageTypesSet) {
SUBCASE("Combination test") {
CAPTURE(spaceType);
CAPTURE(numDimensions);
CAPTURE(numElements);
CAPTURE(storageType);

for (auto [space_type, num_dimensions, num_elements] : {
std::make_tuple(SpaceType::Euclidean, 16, 100),
std::make_tuple(SpaceType::Euclidean, 128, 100),
std::make_tuple(SpaceType::InnerProduct, 256, 100),
std::make_tuple(SpaceType::InnerProduct, 4, 100),
std::make_tuple(SpaceType::InnerProduct, 4, 1000),
}) {
SUBCASE("Jawn") {
CAPTURE(std::make_tuple(space_type, num_dimensions, num_elements));
auto index = TypedIndex<float>(space_type, num_dimensions);
CHECK(toString(index.getSpace()) == toString(space_type));
CHECK(toString(index.getStorageDataType()) == toString(StorageDataType::Float32));
CHECK(index.getNumDimensions() == num_dimensions);
if (storageType == StorageDataType::Float8) {
auto index = TypedIndex<float, int8_t, std::ratio<1, 127>>(spaceType, numDimensions);
testCombination(index, spaceType, numDimensions, storageType);
} else if (storageType == StorageDataType::Float32) {
auto index = TypedIndex<float>(spaceType, numDimensions);
testCombination(index, spaceType, numDimensions, storageType);
} else if (storageType == StorageDataType::E4M3) {
auto index = TypedIndex<float, E4M3>(spaceType, numDimensions);
testCombination(index, spaceType, 20, storageType);
}
}
}
}
}
}
}

0 comments on commit 6b725fb

Please sign in to comment.