def test_backward(self): x = Variable(np.random.rand(1)) y = square(x) y.backward() num_grad = numerical_diff(square, x) flg = np.allclose(x.grad, num_grad) self.assertTrue(flg)
#Importing function from other file from function import square print( "The square of 10 is" + str(square(10)))
def test_function(self, mocked_square): # because you need to patch in exact place where function that has to be mocked is called self.assertEquals(square(5), 1)
def test_function(monkeypatch): monkeypatch.setattr("test_function_pytest.square", lambda x: 1) assert square(5) == 1
from function import square print(square(10))
def test_forward(self): input = np.array(np.random.rand(1)) x = Variable(input) y = square(x) expected = input**2 self.assertEqual(y.data, expected)
from function import square i = 1 while i <= 10: print(square(i)) i = i + 1
from function import square val = input("Enter the value to be squared: ") val = int(val) print(square(val))
x = int(input('Enter the number to square: ')) from function import square print('square of {} is {}'.format(x, square(x)))
from function import Pattern, sine, square import common from random import randint from time import sleep, time from color import Color DELAY = .02 device = "/dev/serial0" ch = Chandelier() ch.open(device) ch.off(BROADCAST) ch.send_entropy() ch.set_brightness(BROADCAST, 100) # TODO: # - check impulse # - fix sin p1 = Pattern(10, square(13, .5), ) try: ch.send_pattern(2, p1) ch.start_pattern(2) sleep(1000000) except KeyboardInterrupt: ch.off(2)
# modules from function import square # classes class Point: def __init__(self, x, y): self.x = x self.y = y p = Point(2, 4) print(square(p.x)) print(square(p.y))
import common from random import randint from time import sleep, time from color import Color DELAY = .02 device = "/dev/serial0" ch = Chandelier() ch.open(device) ch.off(BROADCAST) ch.send_entropy() ch.set_brightness(BROADCAST, 100) # TODO: # - check impulse # - fix sin p1 = Pattern( 10, square(13, .5), ) try: ch.send_pattern(2, p1) ch.start_pattern(2) sleep(1000000) except KeyboardInterrupt: ch.off(2)