-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use doctest and add combination var checks
- Loading branch information
1 parent
321805d
commit 6b725fb
Showing
3 changed files
with
41 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN | ||
#include "doctest.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |