Skip to content

Commit

Permalink
Tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
SuldinVyacheslav committed Dec 19, 2022
1 parent 2d44dce commit cf3404b
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ jobs:
path: ./
- id: set_upload_url
run: |
upload_url=`cat ./upload_url`
echo upload_url=$upload_url >> $GITHUB_OUTPUT
upload_url=cat ./upload_url
echo upload_url="$upload_url" >> "$GITHUB_OUTPUT"
- name: Upload to Release
id: upload_to_release
Expand All @@ -328,5 +328,7 @@ jobs:
- name: Super-Linter
uses: github/[email protected]
env:
VALIDATE_BASH: false
VALIDATE_YAML: false
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
paper
presentation
build/
build/
super-linter.log
9 changes: 9 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ set(Sources
Test.cpp
)


file(GLOB SRC
"*.h"
"../src/*.cpp"
)


add_library(lib ${SRC})
add_executable(${This} ${Sources})

target_link_libraries(${This} PUBLIC
gtest_main
lib
)

add_test(
Expand Down
77 changes: 76 additions & 1 deletion test/Test.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,78 @@
// Copyright 2022 Suldin Vyacheslav

#include <gtest/gtest.h>

TEST(Example, demon) { EXPECT_TRUE(true); }
#include "Physics.h"

using std::pair;
using std::vector;


#define EPS 0.00001

bool d_eq(double A, double B) {
return (fabs(A - B) < EPS);
}

bool Vector_eq(Vector v, Vector u) { return d_eq(v.x, u.x) && d_eq(v.y, u.y) && d_eq(v.z, u.z); }

TEST(Laws, kinetic) {
vector<Molecule> molecules;
molecules.reserve(NUMBER_OF_MOLECULES);
setup_positions(&molecules);

int step = 0;
double initial_kinetic = 0;

for (int i = 0; i < molecules.size(); i++) {
initial_kinetic += molecules[i].velocity.length();
}
double max = initial_kinetic;
double min = initial_kinetic;
while (step++ != 10000) {
calc_force(&molecules);

for (int i = 0; i < molecules.size(); i++) {
molecules[i].semi_step();
}

double velocity = 0;
for (int i = 0; i < molecules.size(); i++) {
velocity += molecules[i].velocity.length();
}
if (max < velocity) {
max = velocity;
}
if (min > velocity) {
min = velocity;
}

EXPECT_TRUE(min > initial_kinetic * 0.8);
EXPECT_TRUE(max < initial_kinetic * 1.2);
}
}

TEST(Inertia, center) {
vector<Molecule> molecules{Molecule(null(), null()),
Molecule(Vector(3, 3, 3), null()),
Molecule(Vector(-5, 4, 2), null())};

Vector center = calc_inertia_center(molecules);
EXPECT_TRUE(Vector_eq(center, Vector(-2, 7, 5) / 3));
}

TEST(Inertia, force) {
vector<Molecule> molecules{Molecule(Vector(1, 1, -1), null()),
Molecule(Vector(3, 3, 3), null()),
Molecule(Vector(-5, 4, 2), null())};

Vector prev_center = null();
Vector center = calc_inertia_center(molecules);

molecules[0].force = Delta(null(), Vector(2, 2, 2));
molecules[1].force = Delta(null(), Vector(0, 1, 4));
molecules[2].force = Delta(null(), Vector(1, 4, -1));
calc_iner_force(&molecules, Delta(prev_center, center));
EXPECT_TRUE(Vector_eq(molecules[2].iner_force.cur,
Vector(-0.596285, -0.596285, -2.98142)));
}

0 comments on commit cf3404b

Please sign in to comment.