From 0390fe8b8e0aa7285a0b7d76f8f2878d33ef3b18 Mon Sep 17 00:00:00 2001 From: David Madl Date: Sun, 1 Mar 2026 23:47:54 +0100 Subject: [PATCH] unit tests: Load_npy_matrix --- google-tests/CMakeLists.txt | 4 +++- google-tests/test1.cpp | 26 +++++++++++++++++++++++++- google-tests/test1/data1.npy | Bin 0 -> 160 bytes 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 google-tests/test1/data1.npy diff --git a/google-tests/CMakeLists.txt b/google-tests/CMakeLists.txt index f47692c..6a7f103 100644 --- a/google-tests/CMakeLists.txt +++ b/google-tests/CMakeLists.txt @@ -4,12 +4,14 @@ set(CMAKE_CXX_STANDARD 20) # 'lib' is the folder with Google Test sources add_subdirectory(lib) -include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) +include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR} libnpy/include) # 'Google_Tests_run' is the target name # 'test1.cpp test2.cpp' are source files with tests add_executable(Google_Tests_run test1.cpp) +file(COPY test1/data1.npy DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test1) + target_link_libraries(Google_Tests_run pasada) #target_include_directories(Google_Tests_run PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/pasada-lib/include") diff --git a/google-tests/test1.cpp b/google-tests/test1.cpp index bb2e03c..e549c62 100644 --- a/google-tests/test1.cpp +++ b/google-tests/test1.cpp @@ -3,6 +3,10 @@ // #include #include "library.h" +#include "npy.hpp" +#include +#include +#include // Demonstrate some basic assertions. TEST(HelloTest, BasicAssertions) { @@ -12,4 +16,24 @@ TEST(HelloTest, BasicAssertions) { EXPECT_EQ(7 * 6, 42); printf("asdf"); hello(); -} \ No newline at end of file +} + +TEST(HelloTest, Load_npy_matrix) { + // "C:\\Users\\david\\Documents\\src\\libpasada\\cmake-build-debug\\google-tests" + std::cout << std::filesystem::current_path() << std::endl; + const std::string path {"test1/data1.npy"}; + npy::npy_data d = npy::read_npy(path); + std::vector data = d.data; + std::vector shape = d.shape; + bool fortran_order = d.fortran_order; + + std::vector expect_shape {2, 2}; + std::vector expect_data {1.0, 2.0, 3.0, 4.0}; + + EXPECT_EQ(shape, expect_shape); + EXPECT_EQ(fortran_order, false); + EXPECT_DOUBLE_EQ(data[0], expect_data[0]); + EXPECT_DOUBLE_EQ(data[1], expect_data[1]); + EXPECT_DOUBLE_EQ(data[2], expect_data[2]); + EXPECT_DOUBLE_EQ(data[3], expect_data[3]); +} diff --git a/google-tests/test1/data1.npy b/google-tests/test1/data1.npy new file mode 100644 index 0000000000000000000000000000000000000000..1a5f0c4a86e9418046dfc33302700515824bd2aa GIT binary patch literal 160 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1ZlV+i=qoAIaUsO_*m=~X4l#&V(cT3DEP6dh= mXCxM+0{I$7ItoUbItsN4WCJb+F!*2(p&1+?GzXLxZ~y@7nH_cj literal 0 HcmV?d00001