示例#1
0
 def test_complicated_complex_number_operations2(self):
     number1 = ComplexNum(3, 4)
     number2 = ComplexNum(1, 2)
     number3 = ComplexNum(3.02, 7.4)
     self.assertTrue((abs(number1) * number2 * number3 -
                      number3 / number1).eq_with_precision(
                          ComplexNum(-60.4464, 66.7952)))
示例#2
0
 def test_complicated_complex_number_operations1(self):
     number1 = ComplexNum(3, 4)
     number2 = ComplexNum(1, 2)
     number3 = ComplexNum(3.02, 7.4)
     number4 = ComplexNum(3.88, 4.2)
     self.assertTrue(
         ((abs(number1) + number2 / number1) * number3 -
          number4).eq_with_precision(ComplexNum(11.9568, 36.2976)))
示例#3
0
 def click_convert(self):
     first_c_n = self.get_complex_num_as_list_from_string(
         self.first_complex_num)
     first_complex_num = ComplexNum(first_c_n.real, first_c_n.imag)
     second_c_n = self.get_complex_num_as_list_from_string(
         self.second_complex_num)
     second_complex_num = ComplexNum(second_c_n.real, second_c_n.imag)
     if self.operation == '+':
         self.answer_text = str(first_complex_num + second_complex_num)
     elif self.operation == '-':
         self.answer_text = str(first_complex_num - second_complex_num)
     elif self.operation == '*':
         self.answer_text = str(first_complex_num * second_complex_num)
     elif self.operation == '/':
         try:
             self.answer_text = str(first_complex_num / second_complex_num)
         except:
             result = 'Error! Cannot divide by zero!'
             self.answer_text = str(result)
     elif self.operation == '==':
         self.answer_text = str(first_complex_num == second_complex_num)
     elif self.operation == '!=':
         self.answer_text = str(first_complex_num != second_complex_num)
示例#4
0
 def test_equal_complex_number_with_float(self):
     number1 = ComplexNum(3.3, 0)
     self.assertTrue(number1 == 3.3)
示例#5
0
 def test_equal_complex_number_with_int(self):
     number1 = ComplexNum(2, 0)
     self.assertTrue(number1 == 2)
示例#6
0
 def test_divide_int_by_complex_number(self):
     number = ComplexNum(3, 4)
     self.assertEqual(25 / number, ComplexNum(3, -4))
示例#7
0
 def test_add_complex_number_and_int(self):
     number = ComplexNum(1, 2)
     self.assertEqual(number + 4, ComplexNum(5, 2))
示例#8
0
 def test_multiply_complex_number_by_float(self):
     number1 = ComplexNum(1, 2)
     self.assertEqual(number1 * 0.3, ComplexNum(0.3, 0.6))
示例#9
0
 def test_sub_complex_number_and_int(self):
     number1 = ComplexNum(1, 2)
     self.assertEqual(number1 - 1, ComplexNum(0, 2))
示例#10
0
 def test_abs_complex_numbers(self):
     number = ComplexNum(3, 4)
     self.assertEqual(abs(number), 5)
示例#11
0
 def test_not_equal_re_complex_numbers(self):
     number1 = ComplexNum(1, 2)
     number2 = ComplexNum(3, 2)
     self.assertTrue(number1 != number2)
示例#12
0
 def test_can_create_real_num(self):
     number = ComplexNum(1)
     self.assertTrue(number.re == 1 and number.im == 0)
示例#13
0
 def test_conjugate_complex_numbers(self):
     number = ComplexNum(1, 2)
     self.assertEqual(number.conjugate(), ComplexNum(1, -2))
示例#14
0
 def test_negative_complex_number(self):
     number1 = ComplexNum(1, 2)
     self.assertEqual(-number1, ComplexNum(-1, -2))
示例#15
0
 def test_sub_int_and_complex_number(self):
     number1 = ComplexNum(1, 2)
     self.assertEqual(1 - number1, ComplexNum(0, -2))
示例#16
0
 def test_sub_float_and_complex_number(self):
     number1 = ComplexNum(1, 2)
     self.assertTrue((0.7 - number1).eq_with_precision(ComplexNum(-0.3,
                                                                  -2)))
示例#17
0
 def test_not_equal_complex_number_with_int(self):
     number1 = ComplexNum(1, 2)
     self.assertTrue(number1 != 3)
示例#18
0
 def test_sub_complex_numbers(self):
     number1 = ComplexNum(1, 2)
     number2 = ComplexNum(3, 4)
     self.assertEqual(number1 - number2, ComplexNum(-2, -2))
示例#19
0
 def test_can_create_zero_complex_num(self):
     number = ComplexNum()
     self.assertTrue(isinstance(number, ComplexNum))
示例#20
0
 def test_divide_complex_numbers(self):
     number1 = ComplexNum(1, 2)
     number2 = ComplexNum(3, 4)
     self.assertEqual(number1 / number2, ComplexNum(0.44, 0.08))
示例#21
0
 def test_multiply_complex_numbers(self):
     number1 = ComplexNum(1, 2)
     number2 = ComplexNum(3, 4)
     self.assertEqual(number1 * number2, ComplexNum(-5, 10))
示例#22
0
 def test_divide_complex_number_by_int(self):
     number = ComplexNum(1, 2)
     self.assertEqual(number / 2, ComplexNum(0.5, 1))
示例#23
0
 def test_multiply_complex_number_by_int(self):
     number1 = ComplexNum(1, 2)
     self.assertEqual(number1 * 7, ComplexNum(7, 14))
示例#24
0
 def test_sub_complex_number_and_float(self):
     number1 = ComplexNum(1, 2)
     self.assertTrue((number1 - 0.7).eq_with_precision(ComplexNum(0.3, 2)))
示例#25
0
 def test_divide_complex_number_by_float(self):
     number = ComplexNum(1, 2)
     self.assertEqual(number / 0.1, ComplexNum(10, 20))
示例#26
0
 def test_can_create_complex_num(self):
     number = ComplexNum(12, 0.23)
     self.assertTrue(number.re == 12 and number.im == 0.23)
示例#27
0
 def test_divide_float_by_complex_number(self):
     number = ComplexNum(3, 4)
     self.assertEqual(0.25 / number, ComplexNum(0.03, -0.04))
示例#28
0
 def test_can_print_complex_number(self):
     number = ComplexNum(12, 0.23)
     self.assertEqual('12 + 0.23i', str(number))
示例#29
0
 def test_can_print_complex_number_with_neg_im(self):
     number = ComplexNum(12, -0.23)
     self.assertEqual('12 - 0.23i', str(number))
示例#30
0
 def test_add_complex_number_and_float(self):
     number = ComplexNum(1, 2)
     self.assertEqual(number + 0.3, ComplexNum(1.3, 2))