Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions hands_on/local_maxima/local_maxima.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import numpy as np

def local_maxima(numlist):
#numlist = input('enter list')
loc = 0
curr = numlist[0]
for idx, elem in enumerate(numlist):
if elem>curr:
loc = idx
curr = elem
print(loc)
return loc

#local_maxima([1, 3, -1, 2, 1])
#local_maxima([1,4,-5,0,2,1])
#local_maxima([-1,-1,0,1])
22 changes: 22 additions & 0 deletions hands_on/numerical_fuzzing/test_var.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#Create a directory called numerical_fuzzing in hands_on.
#In a module called test_var.py, write two tests for the variance function, numpy.var:
# First, a deterministic test
# Then, a numerical fuzzing test
from math import isclose
import numpy
from numpy import testing

def test_var_deterministic():
x = numpy.array([-2.0, 2.0, 6.0])
expected = 10.6
assert isclose(numpy.var(x), expected, abs_tol = 0.1)

def test_var_fuzzing():
rand_state = numpy.random.RandomState(1333)
N, D = 100000, 5
#Goal var: [0.1 , 0.45, 0.8 , 1.15, 1.5]
expected = numpy.linspace(0.1, 1.5, D)
# Generate random, D-dimensional data with the desired mean
x = rand_state.randn(N, D) * expected
vars = numpy.var(x, axis=0)
numpy.testing.assert_allclose(vars, expected*expected, rtol=1e-2)
34 changes: 34 additions & 0 deletions hands_on/pyanno_voting/test_something.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from math import isclose
import numpy
#from numpy import assert_array_equal

def test_floating():
assert isclose(1.1 + 2.2, 3.3)

#def test_tol():
# assert isclose(1.1 + 2.2, abs_tol=0.1)

def test_arraysum():
x = numpy.array([1,1])
y = numpy.array([2,2])
z = numpy.array([3,3])
assert all(x + y == z)
#assert_array_equal(x + y, z)


def test_arithmetic():
assert 1 == 1
assert 2 * 3 == 6

def test_len_list():
lst = ['a', 'b', 'c']
assert len(lst) == 3

def test_equalthree():
assert 1 + 2 == 3

def test_truthy():
assert 1

#def test_floatsum():
# assert 1.1 + 2.2 == 3.3