# Only works for x, y > 0 for all x, y in Z from math import floor, log10, sqrt def add(x, y): return floor(sqrt(10**(2*log10(x)) + 2 * 10**(log10(x) + log10(y)) + 10**(2*log10(y))))
import numpy- # Only works for x, y > 0 for all x, y in Z
- from math import floor, log10, sqrt
- def add(x, y):
if x == 0 and y == 0:return 0elif y == 0:return add(x - numpy.sign(x), 0) + numpy.sign(x)else:return add(x, y - numpy.sign(y)) + numpy.sign(y)- return floor(sqrt(10**(2*log10(x)) + 2 * 10**(log10(x) + log10(y)) + 10**(2*log10(y))))
import unittest class MyTest(unittest.TestCase): def test0(self): self.assertEqual(add(3,4), 7) def test1(self): self.assertEqual(add(1,5), 6) def test2(self): self.assertEqual(add(78,81), 159) def test3(self): self.assertEqual(add(9,21), 30) def test4(self): self.assertEqual(add(5,7), 12) if __name__ == '__main__': unittest.main()
- import unittest
- class MyTest(unittest.TestCase):
- def test0(self):
- self.assertEqual(add(3,4), 7)
- def test1(self):
self.assertEqual(add(5,5), 10)- self.assertEqual(add(1,5), 6)
- def test2(self):
self.assertEqual(add(9,9), 18)- self.assertEqual(add(78,81), 159)
- def test3(self):
self.assertEqual(add(-9,-9), -18)- self.assertEqual(add(9,21), 30)
- def test4(self):
self.assertEqual(add(-9,9), 0)def test5(self):self.assertEqual(add(9,-9), 0)- self.assertEqual(add(5,7), 12)
- if __name__ == '__main__':
- unittest.main()
def find_max(arr): return sorted(arr)[-1]
- def find_max(arr):
return 0- return sorted(arr)[-1]
test.assert_equals(find_max([1, 2, 3, 4, 5]), 5) test.assert_equals(find_max([1, 3, 2, 1, 2]), 3) test.assert_equals(find_max([9, 1, 5, 6, 7]), 9) test.assert_equals(find_max([5, 4, 3, 2, 1]), 5)
# TODO: Replace examples and use TDD by writing your own tests# These are some of the methods available:# test.expect(boolean, [optional] message)# test.assert_equals(actual, expected, [optional] message)# test.assert_not_equals(actual, expected, [optional] message)# You can use Test.describe and Test.it to write BDD style test groupingstest.assert_equals(find_max([1, 2, 3, 4, 5]), 5)- test.assert_equals(find_max([1, 2, 3, 4, 5]), 5)
- test.assert_equals(find_max([1, 3, 2, 1, 2]), 3)
- test.assert_equals(find_max([9, 1, 5, 6, 7]), 9)
- test.assert_equals(find_max([5, 4, 3, 2, 1]), 5)