<commit_before>#include <catch.hpp>
#include "../physics/vec2.h"


bool operator==(const vec2& lhs, const vec2 &rhs) {
	return lhs.x() == Approx(rhs.x())
		&& lhs.y() == Approx(rhs.y());
}

std::ostream& operator<<(std::ostream& s, const vec2 &v) {
	return s << "vec2{" << v.x() << " , " << v.y() << "}";
}

namespace test_vec2 {
	SCENARIO( "assignment" ) {
		GIVEN("empty vector") {
			vec2 v;
			REQUIRE(v.x() == 0);
			REQUIRE(v.y() == 0);

			WHEN("assign x") {
				v.x(8);
				THEN("only x changed") {
					REQUIRE(v.x() > 0);
					REQUIRE(v.x() == Approx(8));
					REQUIRE(v.y() == Approx(0));
				}
			}

			WHEN("assign y") {
				v.y(-2.1);
				THEN("only y changed") {
					REQUIRE(v.y() < 0);
					REQUIRE(v.y() == Approx(-2.1));
					REQUIRE(v.x() == Approx(0));
				}
			}

			WHEN("assign to another vector") {
				const vec2 v2{5,6};
				v = v2;
				THEN("both coordinates changed") {
					REQUIRE(v.x() == Approx(v2.x()));
					REQUIRE(v.y() == Approx(v2.y()));
				}
			}
		}

		GIVEN("vector copy constructed from another ") {
			const vec2 v2(7, 8);
			vec2 v(v2);
			SECTION("both coordinates are equal to another ones") {
				REQUIRE(v.x() == Approx(v2.x()));
				REQUIRE(v.y() == Approx(v2.y()));
			}
		}
	}

	SCENARIO("length") {
		GIVEN("default constructed vector") {
			vec2 v{};
			SECTION("length is 0")
				REQUIRE(v.length() == 0);
		}
		GIVEN("some vector") {
			vec2 v1{1,0}, v2{0,1}, v3{3,4};
			SECTION("length is present") {
				REQUIRE(v1.length() == Approx(1));
				REQUIRE(v2.length() == Approx(1));
				REQUIRE(v3.length() == Approx(5));
			}
		}
	}
	SCENARIO("negation vector") {
		GIVEN("zero vector")
			SECTION("result is zero")
				REQUIRE( -vec2() == vec2());

		GIVEN("positive vector")
			SECTION("result has negative coordinates")
				REQUIRE( -vec2(1,4) == vec2(-1,-4));
		
		GIVEN("negative vector")
			SECTION("result has positive coordinates")
				REQUIRE( -vec2(-3,-1) == vec2(3,1));
	}

	SCENARIO("from two points") {
		GIVEN("2 zero vectors") {
			vec2 a{}, b{};
			SECTION("result is zero") {
				auto r = vec2::from_two_points(a,b);
				REQUIRE(r.x() == Approx(0));
				REQUIRE(r.y() == Approx(0));
			}
		}
		GIVEN("2 same vectors") {
			vec2 a{10,12}, b{a};
			SECTION("result is zero") {
				auto r = vec2::from_two_points(a,b);
				REQUIRE(r.x() == Approx(0));
				REQUIRE(r.y() == Approx(0));
			}
		}
		GIVEN("zero and some vectors") {
			vec2 a{0,0}, b{3,5};
			SECTION("result is second") {
				auto r = vec2::from_two_points(a,b);
				REQUIRE(r.x() == Approx(b.x()));
				REQUIRE(r.y() == Approx(b.y()));
			}
			SECTION("backwards is -second") {
				auto r = vec2::from_two_points(b,a);
				REQUIRE(r.x() == Approx(-b.x()));
				REQUIRE(r.y() == Approx(-b.y()));
			}
		}
	}

	SCENARIO("addition") {
		GIVEN("zero and 2 some vectors") {
			vec2 z{}, x{1,3}, y{9,5};
			WHEN("zero + zero") {
				THEN("result is zero")
					REQUIRE((z+z) == z);
			}
			WHEN("zero += zero") {
				auto r = z;
				r+=z;
				THEN("result is zero")
					REQUIRE(r == z);
			}
			WHEN("zero + x") {
				THEN("result is x")
					REQUIRE((z+x) == x);
			}
			WHEN("zero += x") {
				auto r = z;<commit_msg>use equality operator in tests<commit_after>#include <catch.hpp>
#include "../physics/vec2.h"


bool operator==(const vec2& lhs, const vec2 &rhs) {
	return lhs.x() == Approx(rhs.x())
		&& lhs.y() == Approx(rhs.y());
}

std::ostream& operator<<(std::ostream& s, const vec2 &v) {
	return s << "vec2{" << v.x() << " , " << v.y() << "}";
}

namespace test_vec2 {
	SCENARIO( "assignment" ) {
		GIVEN("empty vector") {
			vec2 v;
			REQUIRE(v.x() == 0);
			REQUIRE(v.y() == 0);

			WHEN("assign x") {
				v.x(8);
				THEN("only x changed") {
					REQUIRE(v.x() > 0);
					REQUIRE(v.x() == Approx(8));
					REQUIRE(v.y() == Approx(0));
				}
			}

			WHEN("assign y") {
				v.y(-2.1);
				THEN("only y changed") {
					REQUIRE(v.y() < 0);
					REQUIRE(v.y() == Approx(-2.1));
					REQUIRE(v.x() == Approx(0));
				}
			}

			WHEN("assign to another vector") {
				const vec2 v2{5,6};
				v = v2;
				THEN("both coordinates changed") {
					REQUIRE(v.x() == Approx(v2.x()));
					REQUIRE(v.y() == Approx(v2.y()));
				}
			}
		}

		GIVEN("vector copy constructed from another ") {
			const vec2 v2(7, 8);
			vec2 v(v2);
			SECTION("both coordinates are equal to another ones") {
				REQUIRE(v.x() == Approx(v2.x()));
				REQUIRE(v.y() == Approx(v2.y()));
			}
		}
	}

	SCENARIO("length") {
		GIVEN("default constructed vector") {
			vec2 v{};
			SECTION("length is 0")
				REQUIRE(v.length() == 0);
		}
		GIVEN("some vector") {
			vec2 v1{1,0}, v2{0,1}, v3{3,4};
			SECTION("length is present") {
				REQUIRE(v1.length() == Approx(1));
				REQUIRE(v2.length() == Approx(1));
				REQUIRE(v3.length() == Approx(5));
			}
		}
	}
	SCENARIO("negation vector") {
		GIVEN("zero vector")
			SECTION("result is zero")
				REQUIRE( -vec2() == vec2());

		GIVEN("positive vector")
			SECTION("result has negative coordinates")
				REQUIRE( -vec2(1,4) == vec2(-1,-4));
		
		GIVEN("negative vector")
			SECTION("result has positive coordinates")
				REQUIRE( -vec2(-3,-1) == vec2(3,1));
	}

	SCENARIO("from two points") {
		GIVEN("2 zero vectors") {
			vec2 a{}, b{};
			SECTION("result is zero") {
				REQUIRE(vec2::from_two_points(a,b) == vec2(0,0));
			}
		}
		GIVEN("2 same vectors") {
			vec2 a{10,12}, b{a};
			SECTION("result is zero") {
				REQUIRE(vec2::from_two_points(a,b) == vec2(0,0));
			}
		}
		GIVEN("zero and x") {
			vec2 z{0,0}, x{3,5};
			SECTION("result is x") {
				REQUIRE(vec2::from_two_points(z,x) == x);
			}
			SECTION("backwards is -x") {
				REQUIRE(vec2::from_two_points(x,z) == -x);
			}
		}
	}

	SCENARIO("addition") {
		GIVEN("zero and 2 some vectors") {
			vec2 z{}, x{1,3}, y{9,5};
			WHEN("zero + zero") {
				THEN("result is zero")
					REQUIRE((z+z) == z);
			}
			WHEN("zero += zero") {
				auto r = z;
				r+=z;
				THEN("result is zero")
					REQUIRE(r == z);
			}
			WHEN("zero + x") {
				THEN("result is x")
					REQUIRE((z+x) == x);
			}
			WHEN("zero += x") {
				auto r = z;
{'fraction_non_alphanumeric': 0.22797156554802447, 'fraction_numerical': 0.03141015043808894, 'mean_word_length': 2.860880663688577, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7289613', 'n_tokens_mistral': 3083, 'n_tokens_neox': 2607, 'n_words': 496}