Skip to content

Commit

Permalink
lab1 (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugelka authored Oct 12, 2024
1 parent 9e44a36 commit ff55152
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions modules/complex-number/test/test_Mironov_Ilya_complex_number.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2024 Mironov Ilya

#include <gtest/gtest.h>

#include "include/complex_number.h"

TEST(Mironov_Ilya_ComplexNumberTest, Can_Add_Negative_Complex_Numbers) {
ComplexNumber z1(-1.2, -2.2);
ComplexNumber z2(-3.2, -4.2);

ComplexNumber ans = z1 + z2;

ASSERT_DOUBLE_EQ(-4.4, ans.getRe());
ASSERT_DOUBLE_EQ(-6.4, ans.getIm());
}

TEST(Mironov_Ilya_ComplexNumberTest, Can_Multiply_By_Zero) {
ComplexNumber z1(1.0, 1.0);
ComplexNumber z2(0.0, 0.0);

ComplexNumber ans = z1 * z2;

ASSERT_DOUBLE_EQ(0.0, ans.getRe());
ASSERT_DOUBLE_EQ(0.0, ans.getIm());
}

TEST(Mironov_Ilya_ComplexNumberTest, Can_Subtract_From_Itself) {
ComplexNumber z1(2.5, 3.5);

ComplexNumber ans = z1 - z1;

ASSERT_DOUBLE_EQ(0.0, ans.getRe());
ASSERT_DOUBLE_EQ(0.0, ans.getIm());
}

TEST(Mironov_Ilya_ComplexNumberTest, Can_Divide_By_Itself) {
ComplexNumber z1(3.0, 4.0);

ComplexNumber ans = z1 / z1;

ASSERT_DOUBLE_EQ(1.0, ans.getRe());
ASSERT_DOUBLE_EQ(0.0, ans.getIm());
}

TEST(Mironov_Ilya_ComplexNumberTest, Cant_Divide_By_Zero) {
ComplexNumber z1(0.0, 0.0);
ComplexNumber z2(0.0, 0.0);

ASSERT_ANY_THROW(z1 / z2);
}

0 comments on commit ff55152

Please sign in to comment.