Skip to content

Commit 685469d

Browse files
Added test cases
1 parent ff88511 commit 685469d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

math/quadratic_equations_complex_numbers.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,21 @@ std::array<std::complex<long double>, 2> quadraticEquation(long double a,
7575
return solutions;
7676
}
7777

78+
static void test() {
79+
std::array<std::complex<long double>, 2> realCase{
80+
std::complex<long double>{1, 0}, std::complex<long double>{1, 0}};
81+
assert(quadraticEquation(1, -2, 1) == realCase);
82+
83+
std::array<std::complex<long double>, 2> complexCase{
84+
std::complex<long double>{-2, -1}, std::complex<long double>{-2, 1}};
85+
assert(quadraticEquation(1, 4, 5) == complexCase);
86+
87+
return;
88+
}
89+
7890
int main() {
91+
test();
92+
7993
std::array<std::complex<long double>, 2> aaa = quadraticEquation(1, 1, 1);
8094
std::cout << "The complex roots of x^2 + x + 1 are " << aaa[0] << " and "
8195
<< aaa[1]

0 commit comments

Comments
 (0)