mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2025-09-12 13:18:17 +00:00
Add Google Test setup and one unit test
This commit is contained in:
33
.gitignore
vendored
Normal file
33
.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
hmm_test
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "externals/googletest"]
|
||||
path = externals/googletest
|
||||
url = https://github.com/google/googletest.git
|
11
README.md
11
README.md
@@ -15,8 +15,8 @@ Version | Changes |
|
||||
|
||||
_ID: In Development_
|
||||
|
||||
## FAQ
|
||||
|
||||
## FAQ
|
||||
|
||||
**What's the license?**
|
||||
|
||||
@@ -25,3 +25,12 @@ This library is in the public domain. You can do whatever you want with them.
|
||||
**Where can I contact you to ask questions?**
|
||||
|
||||
You can email me at: Zak@Handmade.Network
|
||||
|
||||
|
||||
## Testing
|
||||
|
||||
```shell
|
||||
cd test
|
||||
make
|
||||
./hmm_test
|
||||
```
|
||||
|
1
externals/googletest
vendored
Submodule
1
externals/googletest
vendored
Submodule
Submodule externals/googletest added at ed9d1e1ff9
5
test/HandmadeMath.cpp
Normal file
5
test/HandmadeMath.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
#define HANDMADE_MATH_IMPLEMENTATION
|
||||
#define HANDMADE_MATH_CPP_MODE
|
||||
#define HANDMADE_MATH_NO_INLINE
|
||||
#include "../HandmadeMath.h"
|
81
test/Makefile
Normal file
81
test/Makefile
Normal file
@@ -0,0 +1,81 @@
|
||||
# A sample Makefile for building Google Test and using it in user
|
||||
# tests. Please tweak it to suit your environment and project. You
|
||||
# may want to move it to your project's root directory.
|
||||
#
|
||||
# SYNOPSIS:
|
||||
#
|
||||
# make [all] - makes everything.
|
||||
# make TARGET - makes the given target.
|
||||
# make clean - removes all files generated by make.
|
||||
|
||||
# Please tweak the following variable definitions as needed by your
|
||||
# project, except GTEST_HEADERS, which you can use in your own targets
|
||||
# but shouldn't modify.
|
||||
|
||||
# Points to the root of Google Test, relative to where this file is.
|
||||
# Remember to tweak this if you move this file.
|
||||
GTEST_DIR = ../externals/googletest/googletest
|
||||
|
||||
# Where to find user code.
|
||||
USER_DIR = ..
|
||||
|
||||
# Flags passed to the preprocessor.
|
||||
# Set Google Test's header directory as a system directory, such that
|
||||
# the compiler doesn't generate warnings in Google Test headers.
|
||||
CPPFLAGS += -isystem $(GTEST_DIR)/include
|
||||
|
||||
# Flags passed to the C++ compiler.
|
||||
CXXFLAGS += -g -Wall -Wextra -pthread -Wno-missing-braces -Wno-missing-field-initializers
|
||||
|
||||
# All tests produced by this Makefile. Remember to add new tests you
|
||||
# created to the list.
|
||||
TESTS = hmm_test
|
||||
|
||||
# All Google Test headers. Usually you shouldn't change this
|
||||
# definition.
|
||||
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
|
||||
$(GTEST_DIR)/include/gtest/internal/*.h
|
||||
|
||||
# House-keeping build targets.
|
||||
|
||||
all : $(TESTS)
|
||||
|
||||
clean :
|
||||
rm -f $(TESTS) gtest.a gtest_main.a *.o
|
||||
|
||||
# Builds gtest.a and gtest_main.a.
|
||||
|
||||
# Usually you shouldn't tweak such internal variables, indicated by a
|
||||
# trailing _.
|
||||
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
|
||||
|
||||
# For simplicity and to avoid depending on Google Test's
|
||||
# implementation details, the dependencies specified below are
|
||||
# conservative and not optimized. This is fine as Google Test
|
||||
# compiles fast and for ordinary users its source rarely changes.
|
||||
gtest-all.o : $(GTEST_SRCS_)
|
||||
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
|
||||
$(GTEST_DIR)/src/gtest-all.cc
|
||||
|
||||
gtest_main.o : $(GTEST_SRCS_)
|
||||
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
|
||||
$(GTEST_DIR)/src/gtest_main.cc
|
||||
|
||||
gtest.a : gtest-all.o
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
gtest_main.a : gtest-all.o gtest_main.o
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
# Builds a sample test. A test should link with either gtest.a or
|
||||
# gtest_main.a, depending on whether it defines its own main()
|
||||
# function.
|
||||
|
||||
HandmadeMath.o : $(USER_DIR)/test/HandmadeMath.cpp $(USER_DIR)/HandmadeMath.h $(GTEST_HEADERS)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/test/HandmadeMath.cpp
|
||||
|
||||
hmm_test.o : $(USER_DIR)/test/hmm_test.cpp $(GTEST_HEADERS)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/test/hmm_test.cpp
|
||||
|
||||
hmm_test : HandmadeMath.o hmm_test.o gtest_main.a
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@
|
51
test/hmm_test.cpp
Normal file
51
test/hmm_test.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
#define HANDMADE_MATH_CPP_MODE
|
||||
#include "../HandmadeMath.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
TEST(Initialization, Vectors)
|
||||
{
|
||||
//
|
||||
// Test vec2
|
||||
//
|
||||
hmm_vec2 v2 = HMM_Vec2(1.0f, 2.0f);
|
||||
hmm_vec2 v2i = HMM_Vec2(1, 2);
|
||||
|
||||
EXPECT_FLOAT_EQ(v2.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v2.Elements[1], 2.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(v2i.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v2i.Elements[1], 2.0f);
|
||||
|
||||
//
|
||||
// Test vec3
|
||||
//
|
||||
hmm_vec3 v3 = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
hmm_vec3 v3i = HMM_Vec3i(1, 2, 3);
|
||||
|
||||
EXPECT_FLOAT_EQ(v3.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v3.Elements[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v3.Elements[2], 3.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(v3i.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.Elements[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.Elements[2], 3.0f);
|
||||
|
||||
//
|
||||
// Test vec4
|
||||
//
|
||||
hmm_vec4 v4 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_vec4 v4i = HMM_Vec4i(1, 2, 3, 4);
|
||||
|
||||
EXPECT_FLOAT_EQ(v4.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v4.Elements[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v4.Elements[2], 3.0f);
|
||||
EXPECT_FLOAT_EQ(v4.Elements[3], 4.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(v4i.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.Elements[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.Elements[2], 3.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.Elements[3], 4.0f);
|
||||
}
|
Reference in New Issue
Block a user