Skip to content

complex-numbers: update tests to v1.3.0 #1333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 37 additions & 26 deletions exercises/complex-numbers/complex_numbers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,40 @@
from complex_numbers import ComplexNumber


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0

# Tests adapted from `problem-specifications//canonical-data.json` @ v1.3.0

class ComplexNumbersTest(unittest.TestCase):

def test_real_part_of_a_purely_real_number(self):
input_number = ComplexNumber(1, 0)
self.assertEqual(input_number.real, 1)

def test_real_part_of_a_purely_imaginary_number(self):
input_number = ComplexNumber(0, 1)
self.assertEqual(input_number.real, 0)

def test_real_part_of_a_number_with_real_and_imaginary_part(self):
input_number = ComplexNumber(1, 2)
self.assertEqual(input_number.real, 1)

def test_imaginary_part_of_a_purely_real_number(self):
input_number = ComplexNumber(1, 0)
self.assertEqual(input_number.imaginary, 0)

def test_imaginary_part_of_a_purely_imaginary_number(self):
input_number = ComplexNumber(0, 1)
self.assertEqual(input_number.imaginary, 1)

def test_imaginary_part_of_a_number_with_real_and_imaginary_part(self):
input_number = ComplexNumber(1, 2)
self.assertEqual(input_number.imaginary, 2)

def test_imaginary_unit(self):
first_input = ComplexNumber(0, 1)
second_input = ComplexNumber(0, 1)
expected = ComplexNumber(-1, 0)
self.assertEqual(first_input * second_input, expected)

def test_add_purely_real_numbers(self):
first_input = ComplexNumber(1, 0)
second_input = ComplexNumber(2, 0)
Expand Down Expand Up @@ -120,30 +149,6 @@ def test_conjugate_a_number_with_real_and_imaginary_part(self):
self.assertEqual(input_number.conjugate().imaginary,
expected.imaginary)

def test_real_part_of_a_purely_real_number(self):
input_number = ComplexNumber(1, 0)
self.assertEqual(input_number.real, 1)

def test_real_part_of_a_purely_imaginary_number(self):
input_number = ComplexNumber(0, 1)
self.assertEqual(input_number.real, 0)

def test_real_part_of_a_number_with_real_and_imaginary_part(self):
input_number = ComplexNumber(1, 2)
self.assertEqual(input_number.real, 1)

def test_imaginary_part_of_a_purely_real_number(self):
input_number = ComplexNumber(1, 0)
self.assertEqual(input_number.imaginary, 0)

def test_imaginary_part_of_a_purely_imaginary_number(self):
input_number = ComplexNumber(0, 1)
self.assertEqual(input_number.imaginary, 1)

def test_imaginary_part_of_a_number_with_real_and_imaginary_part(self):
input_number = ComplexNumber(1, 2)
self.assertEqual(input_number.imaginary, 2)

def test_eulers_identity_formula(self):
input_number = ComplexNumber(0, math.pi)
expected = ComplexNumber(-1, 0)
Expand All @@ -162,6 +167,12 @@ def test_exponential_of_a_purely_real_number(self):
self.assertEqual(input_number.exp().real, expected.real)
self.assertEqual(input_number.exp().imaginary, expected.imaginary)

def test_exponential_of_a_number_with_real_and_imaginary_part(self):
input_number = ComplexNumber(math.log(2), math.pi)
expected = ComplexNumber(-2, 0)
self.assertEqual(input_number.exp().real, expected.real)
self.assertEqual(input_number.exp().imaginary, expected.imaginary)


if __name__ == '__main__':
unittest.main()