Skip to content

Commit

Permalink
change the task type for WarmUp/MovingOn/HuntingBugs to edu, add test…
Browse files Browse the repository at this point in the history
… for the task

Signed-off-by: Evgenii Moiseenko <[email protected]>
  • Loading branch information
eupp committed Nov 13, 2023
1 parent c039e48 commit 4c02d7e
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 12 deletions.
11 changes: 8 additions & 3 deletions WarmUp/MovingOn/HuntingBugs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ cmake_minimum_required(VERSION 3.22)
project(WarmUp-MovingOn-HuntingBugs)

set(TASK
src/approaching.cpp)
src/collision.cpp src/approaching.cpp)

set(SRC
${TASK} src/main.cpp
src/move.cpp src/point.cpp src/direction.cpp src/borders.cpp src/collision.cpp src/generate.cpp src/loop.cpp)
src/move.cpp src/point.cpp src/direction.cpp src/borders.cpp src/generate.cpp src/loop.cpp)

set(TEST
test/test.cpp)

add_executable(${PROJECT_NAME}-run ${SRC})

configure_test_target(${PROJECT_NAME}-test "${TASK}" ${TEST})

prepare_sfml_framework_lesson_task(
"${CMAKE_CURRENT_SOURCE_DIR}/.."
${PROJECT_NAME}-run
""
${PROJECT_NAME}-test
)
6 changes: 2 additions & 4 deletions WarmUp/MovingOn/HuntingBugs/src/approaching.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include "scene.hpp"

void approachingLoop(Circle player, Circle consumable[], bool concerned[], int size) {
for (int i = 0; i <= size; ++i) {
for (int i = 0; i < size; ++i) {
float dist = distance(player.center, consumable[i].center);
float warnDist = 3 * player.radius + consumable[i].radius;
if (concerned[i] = false) {
concerned[i] = dist < warnDist;
}
concerned[i] = (dist < warnDist);
}
}
20 changes: 16 additions & 4 deletions WarmUp/MovingOn/HuntingBugs/task-info.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
type: ide
type: edu
custom_name: Hunting Bugs
files:
- name: src/approaching.cpp
visible: true
placeholders:
- offset: 113
length: 215
placeholder_text: |-
for (int i = 0; i <= size; ++i) {
float dist = distance(player.center, consumable[i].center);
float warnDist = 3 * player.radius + consumable[i].radius;
if (concerned[i] = false) {
concerned[i] = dist < warnDist;
}
}
- name: src/loop.cpp
visible: true
placeholders:
Expand Down Expand Up @@ -136,7 +149,6 @@ files:
visible: false
- name: src/main.cpp
visible: true
editable: true
- name: src/approaching.cpp
visible: true
- name: test/test.cpp
visible: false
feedback_link: https://docs.google.com/forms/d/e/1FAIpQLScfBp0gzdxWOmXvQVdyNmeO1od7CG7zxLgNUP4LzKxLBCzkhQ/viewform?usp=pp_url&entry.2103429047=Warm+Up/Moving+On/Hunting+Bugs
55 changes: 55 additions & 0 deletions WarmUp/MovingOn/HuntingBugs/test/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <gtest/gtest.h>

#include <cmath>

#include "scene.hpp"
#include "operators.hpp"
#include "testing.hpp"

testing::Environment* const env =
testing::AddGlobalTestEnvironment(new TestEnvironment);

std::string error_msg(Circle player, Circle consumable, bool concerned, bool expected, bool actual) {
std::ostringstream stream;
stream << "Testing statement:\n"
<< " approachingLoop(player, consumable, concerned, N)" << "\n";
stream << "Test data:" << "\n"
<< " player = " << player << "\n"
<< " consumable[i] = " << consumable << "\n"
<< " concerned[i] = " << concerned << "\n";
stream << "Expected result:\n"
<< " concerned[i] = " << expected << "\n";
stream << "Actual result:\n"
<< " concerned[i] = " << actual << "\n";
return stream.str();
}

TEST(collisionLoopTest, collisionLoopTest) {
Circle player = { {0.0f, 0.0f}, RADIUS };

const int N_CIRCLES = 4;

Circle circle1 = { { 3 * RADIUS, 3 * RADIUS }, 2 * RADIUS };
Circle circle2 = { { 2 * RADIUS, -2 * RADIUS }, RADIUS / 2 };
Circle circle3 = { { EAST_BORDER, SOUTH_BORDER }, RADIUS };
Circle circle4 = { { 10 * RADIUS, 6 * RADIUS }, RADIUS / 4 };
Circle circle5 = player;

Circle consumable[N_CIRCLES + 1] = { circle1, circle2, circle3, circle4, circle5 };
bool concerned[N_CIRCLES + 1] = { false, true, false, true, false };
bool expected[N_CIRCLES + 1] = { true, true, false, false, false };

bool actual[N_CIRCLES + 1];
for (int i = 0; i < N_CIRCLES + 1; ++i) {
actual[i] = concerned[i];
}
approachingLoop(player, consumable, actual, N_CIRCLES);

for (int i = 0; i < N_CIRCLES; ++i) {
ASSERT_EQ(expected[i], actual[i]) << error_msg(player, consumable[i], concerned[i], expected[i], actual[i]);
}
ASSERT_EQ(expected[N_CIRCLES], actual[N_CIRCLES])
<< "Testing statement:\n"
<< " approachingLoop(player, consumable, concerned, N)" << "\n"
<< "Function attempted to modify elements of the array outside of its bounds.";
}
2 changes: 1 addition & 1 deletion WarmUp/MovingOn/PlayAround/src/approaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ void approachingLoop(Circle player, Circle consumable[], bool concerned[], int s
for (int i = 0; i < size; ++i) {
float dist = distance(player.center, consumable[i].center);
float warnDist = 3 * player.radius + consumable[i].radius;
concerned[i] = dist < warnDist;
concerned[i] = (dist < warnDist);
}
}
18 changes: 18 additions & 0 deletions WarmUp/MovingOn/PlayAround/task-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ custom_name: Play Around
files:
- name: src/approaching.cpp
visible: true
placeholders:
- offset: 113
length: 215
placeholder_text: |-
for (int i = 0; i <= size; ++i) {
float dist = distance(player.center, consumable[i].center);
float warnDist = 3 * player.radius + consumable[i].radius;
if (concerned[i] = false) {
concerned[i] = dist < warnDist;
}
}
dependency:
section: WarmUp
lesson: MovingOn
task: HuntingBugs
file: src/approaching.cpp
placeholder: 1
is_visible: false
- name: src/loop.cpp
visible: true
placeholders:
Expand Down

0 comments on commit 4c02d7e

Please sign in to comment.