def test_div(self): self.assertEqual(main.div(6, 2), 3) self.assertEqual(main.div(-1, 1), -1) self.assertEqual(main.div(2, 4), 1 / 2) #to check for value error: with self.assertRaises(ValueError): main.div(3, 0)
def test_main(self): self.assertEquals(div(1, 2, 8), "0.4") self.assertEquals(div(1, 12, 10), "0.08(3)") self.assertEquals(div(3, 7, 10), "0.(428571)") self.assertEquals(div(1, 125, 10), "0.008") self.assertEquals(div(14, 3, 3), "11.2") self.assertEquals(div(365, 8, 2), "101101.101")
def test_div(self): self.assertEqual(main.div(6, 3), 2, 'division fail')
from main import gen, div import numpy as np m = [0, 1, 1, 1] g = [1, 1, 1, 0, 1] d = 3 code = gen(m, g, len(g) - 1) lenC = len(code) print(code, div(code.copy(), g)) print("start search...") for i in range(2**len(code)): n = list('{0:b}'.format(i)) # print(m) n = np.array(['0'] * (lenC - len(n)) + n).astype("int32") n = list(n) #print(n) code_noise = np.bitwise_xor(code.copy(), n) #code = gen(m, g, len(g) - 1) result = div(code_noise.copy(), g) if np.sum(result) == 0: if np.sum(n) <= d - 1 and np.sum(n) >= 1: print("message ", m, "code ", code_noise, "noise ", n, "result ", result, np.sum(n))
def test__div__positive_integers(self): result = main.div(6, 2) self.assertEqual(result, 3)
def test__div__zero_denominator(self): with self.assertRaises(ZeroDivisionError): result = main.div(6, 0)
def test__div__zero_numerator(self): result = main.div(0, 2) self.assertEqual(result, 0)
def test__div__negative_integers(self): result = main.div(-6, 2) self.assertEqual(result, -3)
def test_div(): assert div(3, 3) == 1
def test_div(self): self.assertEqual(main.div(10, 5), 2) self.assertEqual(main.div(-5, 5), -1) self.assertEqual(main.div(-5, -5), 1)
button_clear = Button(frame2, text='C', fg='maroon', bg='gray75', font=('comicsans', 12)) button_clear.config(width=6, height=2, command=lambda: main.clear(text_input, text_output)) button_clear.grid(column=0, row=1, padx=1, pady=1) button_div = Button(frame2, text='/', fg='maroon', bg='gray75', font=('comicsans', 12)) button_div.config(width=6, height=2, command=lambda: main.div(text_output)) button_div.grid(column=1, row=1, padx=1, pady=1) button_mul = Button(frame2, text='X', fg='maroon', bg='gray75', font=('comicsans', 12)) button_mul.config(width=6, height=2, command=lambda: main.mul(text_output)) button_mul.grid(column=2, row=1, padx=1, pady=1) button_fact = Button(frame2, text='!', fg='maroon', bg='gray75', font=('comicsans', 12))