Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
242 commits
Select commit Hold shift + click to select a range
797456d
added a readme file
calvinpy Jan 15, 2016
8dfa1d8
added readme file
calvinpy Jan 15, 2016
18ed19f
more changes
calvinpy Jan 15, 2016
0452dde
added a readme file
robertstephen Jan 15, 2016
63f1371
Test
robertstephen Jan 15, 2016
185aa26
added a FizzBuzz file
robertstephen Jan 22, 2016
dd5287a
Updating the mailroom.py file
johnrudolph08 Jan 27, 2016
c1f94c9
cleanup ROT-13 test
gmckeag Jan 28, 2016
a9a569a
Merge remote-tracking branch 'upstream/master'
gmckeag Jan 28, 2016
39462a0
first version
calvinpy Jan 28, 2016
453430c
second version
calvinpy Jan 28, 2016
df50d71
made updates to mailroom
johnrudolph08 Jan 28, 2016
831db99
updatede through 'thank you' mailroom
johnrudolph08 Jan 28, 2016
cec0bce
Revised my fizz_buzz.py program to make it more efficient.
chiho924 Jan 28, 2016
940d6eb
Added list_lab.py, mailroom.py, slicing_lab.py, and string_formatting…
chiho924 Jan 28, 2016
6b4cb1a
Merge remote-tracking branch 'upstream/master'
gmckeag Jan 29, 2016
31c0a45
added dict_lab.py
gmckeag Jan 29, 2016
03e83df
Updating set_lab
johnrudolph08 Jan 29, 2016
3973afd
dict_lab.py is now completed!
chiho924 Jan 29, 2016
f639fad
moved dict_lab
gmckeag Jan 29, 2016
03a193f
re-added dict_lab
gmckeag Jan 29, 2016
acc70f0
Merge remote-tracking branch 'upstream/master'
gmckeag Jan 29, 2016
a063b26
started mailroom.py
gmckeag Jan 29, 2016
ea0465c
worked on print-grid, added new dictionary lab working file
sgrees Jan 29, 2016
20c85fe
add initial mailroom.py
gmckeag Jan 30, 2016
c6642da
Corrected add donation and add donor cases
gmckeag Jan 30, 2016
31949f4
Added Thank you message to donor
gmckeag Jan 30, 2016
25a21eb
finished initial version
gmckeag Jan 30, 2016
ee751f1
Fixed Folder name and classwork on dictionaries
Jan 30, 2016
6de9cf8
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
sgrees Jan 30, 2016
d3beefc
Added the following functions:
Jan 30, 2016
9680ad6
updates
calvinpy Jan 30, 2016
d661e6e
updates
calvinpy Jan 30, 2016
943b398
changed file names for consistency, added and finished MoneyCounting lab
sgrees Jan 30, 2016
acb5df4
Fixed dictionary structure and made dict global for editing ease.
Jan 30, 2016
f437807
mailroom cleanup + added donor data persistence
gmckeag Jan 31, 2016
32c2372
added lists lab working file
sgrees Jan 31, 2016
e2c3222
mailroom.py - cleanup
gmckeag Jan 31, 2016
574a59f
added stringFormatting lab working file, added and finished ROT13 lab
sgrees Jan 31, 2016
e0ce8f6
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
johnrudolph08 Jan 31, 2016
668fb65
Fleshed out more of the send_thank_you() function
Jan 31, 2016
f8a35c9
committing a file
robertstephen Jan 31, 2016
787b5ec
make changes
robertstephen Jan 31, 2016
368cd20
Completed assignment, now just need to add documentation. which i thi…
Jan 31, 2016
823b10c
Cleaned up and tested. Still need docs.
Jan 31, 2016
3211361
Final comments and docs created. All done.
Jan 31, 2016
183174a
Fixed issue with add_donor_donation() not getting the current list of…
Jan 31, 2016
51c8d34
finished mailroom
johnrudolph08 Feb 1, 2016
7d4ae54
last edit to mailroom
johnrudolph08 Feb 1, 2016
dbd0c0f
a few minor tweaks
johnrudolph08 Feb 1, 2016
52040fa
Merge remote-tracking branch 'upstream/master'
gmckeag Feb 2, 2016
691fe3b
Corrected error with sorting dict
johnrudolph08 Feb 2, 2016
94a559e
upload session 4 homework
robertstephen Feb 2, 2016
b3e8180
Merge remote-tracking branch 'upstream/master'
gmckeag Feb 3, 2016
a089cb0
files-lab.py
dholmer Feb 6, 2016
5a55dd2
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
sgrees Feb 7, 2016
7d62788
completed string and file labs, added mailroom lab working file
sgrees Feb 7, 2016
1b9b04a
adding session4 and session5 commits
johnrudolph08 Feb 9, 2016
049d61d
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
sgrees Feb 10, 2016
999cd72
updating progress session 5
johnrudolph08 Feb 10, 2016
8abf379
Labs
mdgregor Feb 11, 2016
bb6f014
Completed Session 5 assignements
Feb 11, 2016
4b9d100
Completed additional exercises.
MikeSchincariol Feb 11, 2016
6cb6ba0
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
MikeSchincariol Feb 11, 2016
65de4ed
Removed dead import statements.
MikeSchincariol Feb 11, 2016
3a1d1b1
added file list and copy scripts
Feb 11, 2016
277410f
Adding Mailroom.py with exceptions
kbindhu Feb 11, 2016
589d531
adding session05
kbindhu Feb 11, 2016
aeccff3
Move closure example to correct session.
Feb 11, 2016
23edf4e
Drop IBAFP since neither I nor Google knows what that means
Feb 11, 2016
3f07ddf
Merge pull request #2 from UWPCE-PythonCert/master
ThreeBbb Feb 11, 2016
7c35f96
Prepping a demo and making some of the material more neutral
Feb 12, 2016
83c45bb
Session 5 related
robertstephen Feb 12, 2016
ce87a3c
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
sgrees Feb 12, 2016
4539214
py.test example
Feb 12, 2016
ec52239
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
Feb 12, 2016
169850c
added session06 folder with cigarparty and exceptions labs, worked on…
sgrees Feb 12, 2016
4fd21a0
add some labs
robertstephen Feb 12, 2016
3e65109
Added tonight's notebooks
Feb 12, 2016
955fdc3
Back ported stuff from the live class into the slides
Feb 12, 2016
37bf696
Labs completed
chiho924 Feb 14, 2016
07fcff5
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
sgrees Feb 14, 2016
1fbc0b2
added working menu function to mailroom lab, half finished thank func…
sgrees Feb 14, 2016
d5143b0
almost completed mailroom lab, only missing back to main menu option
sgrees Feb 14, 2016
752c514
finished trapezoidal.py
Feb 14, 2016
085c2bd
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
Feb 14, 2016
f1a091f
fixed trapezoidal math
Feb 14, 2016
70e2dc1
added more assertions to test the trapezoidal rule
Feb 14, 2016
4b0615b
Merge pull request #77 from gaffneyt/master
rriehle Feb 14, 2016
9c7c7df
delete files
robertstephen Feb 14, 2016
2534f55
updating for sessions 5 and 6 work
johnrudolph08 Feb 15, 2016
0e1b115
submitting my mailroom HW titled Mailroom_b3.py
ThreeBbb Feb 15, 2016
26d747d
Added functions as args list and updated lightning talk schedule
Feb 15, 2016
b95dd7f
Merge branch 'rriehle-2016a-prep'
Feb 15, 2016
07642ea
made more updates to trap
johnrudolph08 Feb 15, 2016
da12439
Merge pull request #54 from gmckeag/master
summerela Feb 15, 2016
8968c49
Merge pull request #61 from calvinfannin/master
summerela Feb 15, 2016
6f1b864
Merge pull request #63 from johnrudolph08/master
summerela Feb 15, 2016
c65bb73
Merge pull request #69 from dholmer/master
summerela Feb 15, 2016
eb0f956
Merge pull request #71 from MikeSchincariol/master
summerela Feb 15, 2016
4944f7a
Merge pull request #72 from bglogowski/master
summerela Feb 16, 2016
9355227
Merge pull request #73 from kbindhu/master
summerela Feb 16, 2016
5971a32
Merge pull request #75 from sgrees/master
summerela Feb 16, 2016
865410a
Revised mailroom.py
chiho924 Feb 16, 2016
1a08883
finishing trapezoid exercise
johnrudolph08 Feb 16, 2016
ee7c733
Updated lightning talk schedule
Feb 17, 2016
c5bb4cd
update dict_lab into session 4 folder (may also include updates to ma…
ThreeBbb Feb 18, 2016
9a8e6e6
Upgraded mailroom.py to use safe_input method.
MikeSchincariol Feb 18, 2016
8d6f4b6
Completed "scoring" assignmet.
MikeSchincariol Feb 18, 2016
3059753
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
MikeSchincariol Feb 18, 2016
400e75f
Completed trapz() assignment.
MikeSchincariol Feb 18, 2016
203c145
Added type information to trapz().
MikeSchincariol Feb 18, 2016
5cf7ef1
Session 6 homework
Feb 18, 2016
9a272bf
add trapezoidal rule and test
robertstephen Feb 18, 2016
7108a42
Finished alternate function passing assn
johnrudolph08 Feb 18, 2016
c6db087
update dict_lab into session 4 folder (may also include updates to ma…
ThreeBbb Feb 18, 2016
152dcc7
update dict_lab into session 4 folder (may also include updates to ma…
ThreeBbb Feb 18, 2016
07f74dc
Merge branch 'master' into rriehle-2016a-prep
Feb 18, 2016
ae88756
Replaced test_trapz.py
Feb 18, 2016
5791502
Updates
Feb 18, 2016
b0e9843
update sherlock trigrams aka kata 14
ThreeBbb Feb 19, 2016
b705b84
adding trapz.py
NewtonMD Feb 19, 2016
616ba2f
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
MikeSchincariol Feb 19, 2016
cd4ace5
adding session 3/4/5
ThreeBbb Feb 19, 2016
14d92d8
files for lightning talk
tsegas Feb 19, 2016
a1a2cfe
support file for lightning talk
tsegas Feb 19, 2016
ed4fcab
adding trapezoidal.py and color.py
kbindhu Feb 19, 2016
599eedf
update
robertstephen Feb 19, 2016
9540ec0
added test_trapz
luisangus Feb 19, 2016
40f1af5
added trapz.py
luisangus Feb 19, 2016
7df298c
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
ThreeBbb Feb 19, 2016
b702ff0
Added the session07 notebook, updated readings, moved multi-inheritance
Feb 19, 2016
ba586b8
Updated lightning talks
Feb 19, 2016
f7faacd
Merge pull request #83 from ThreeBbb/master
summerela Feb 20, 2016
34340ea
Merge pull request #84 from tsegas/master
summerela Feb 20, 2016
61250f4
Merge branch 'master' of github.com:UWPCE-PythonCert/IntroPython2016a
Feb 20, 2016
352ea4f
Merge branch 'master' of git://github.com/lucferros/IntroPython2016a …
Feb 20, 2016
f92a285
Merge branch 'lucferros-master'
Feb 20, 2016
3b16214
Merge branch 'master' of git://github.com/chiho924/IntroPython2016a i…
Feb 20, 2016
da2be3b
Merge branch 'chiho924-master'
Feb 20, 2016
d998c48
Suggestions for fizbuzz
Feb 20, 2016
6d426cf
Merge branch 'chiho924-master'
Feb 20, 2016
f756c32
Merge pull request #79 from johnrudolph08/master
rriehle Feb 20, 2016
fbc7ab2
Merge pull request #80 from MikeSchincariol/master
rriehle Feb 20, 2016
a83ccef
Added html_render.py
chiho924 Feb 21, 2016
c253277
Deanna's Boto slides
Feb 21, 2016
bdb730b
Merge branch 'rriehle-2016a-prep'
Feb 21, 2016
29f5132
Adding Trapezoidal Rule walk-thru
summerrae78-cloud Feb 21, 2016
3921370
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
summerrae78-cloud Feb 21, 2016
2255285
Merge pull request #82 from NewtonMD/master
summerela Feb 21, 2016
39e291b
Merge pull request #85 from kbindhu/master
summerela Feb 21, 2016
bcda4a3
Merge pull request #86 from luisangus/master
summerela Feb 21, 2016
afca745
Merge pull request #81 from robertstephen/master
summerela Feb 21, 2016
a51a2e5
Office hours with Robert
Feb 21, 2016
c470122
Clarify intent
Feb 22, 2016
3324bb6
Added weapon.py
chiho924 Feb 22, 2016
90e3280
Rename
Feb 22, 2016
9ff9775
Comments
Feb 22, 2016
dec3dc9
Merge branch 'rriehle-2016a-prep'
Feb 22, 2016
d044ce5
Adding weapon.py and corresponding test
kbindhu Feb 24, 2016
10f9b8f
Preliminary Session Eight class notes
Feb 24, 2016
2d1d851
Merge pull request #88 from kbindhu/master
rriehle Feb 24, 2016
2176ac5
Updated lightning talks
Feb 24, 2016
39b6496
completed string format lab session_04 and file write lab and student…
ThreeBbb Feb 24, 2016
6662d21
dict lab update and cigar party test results and notes
ThreeBbb Feb 25, 2016
ba4aee0
First cut of html_render.py. 7 of 8 steps complete.
MikeSchincariol Feb 25, 2016
fe40528
Added Meta class.
MikeSchincariol Feb 25, 2016
be0dbab
Bug fix: the A class didn't create the link with the right attribute …
MikeSchincariol Feb 25, 2016
773b19a
lab keyword and score_flowerpower main and test asserts with switchdi…
ThreeBbb Feb 25, 2016
bd272f4
lab_keyword updates to alternative structure for kwargs
ThreeBbb Feb 25, 2016
d83540f
Pytalk files for this evening -ipynb warning changed inotebook LF to …
ThreeBbb Feb 25, 2016
3987753
Updates
Feb 25, 2016
c50a588
Brennen's lightning talk
Feb 25, 2016
765dc82
Updates
Feb 25, 2016
eecd5cc
Merge branch 'rriehle-2016a-prep'
Feb 25, 2016
e59d7b4
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
MikeSchincariol Feb 26, 2016
2b34b09
render html file added
luisangus Feb 26, 2016
a7a5de7
added run file
luisangus Feb 26, 2016
b49242f
Adding HTML Rendering Lab Example
summerrae78-cloud Feb 28, 2016
9e24fe2
Added a notebook
Feb 28, 2016
a0e9fb2
Merge branch 'rriehle-2016a-prep'
Feb 28, 2016
fc5523a
Session08 notebook
Feb 28, 2016
63142b5
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
MikeSchincariol Mar 1, 2016
43ba11c
HTML Render V1
robertstephen Mar 2, 2016
04ae6a1
Merge pull request #87 from chiho924/master
summerela Mar 2, 2016
c212c3e
Merge pull request #89 from MikeSchincariol/master
summerela Mar 2, 2016
b641b18
Added circle class.
MikeSchincariol Mar 3, 2016
75df3a0
Changed alternate constructor to use the "cls" parameter passed in to…
MikeSchincariol Mar 3, 2016
7ab4771
Completed the callable exercise.
MikeSchincariol Mar 3, 2016
d1e671c
Added Sparsearray homework.
MikeSchincariol Mar 3, 2016
24ec3ed
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
MikeSchincariol Mar 3, 2016
cfae559
Merge pull request #90 from luisangus/master
summerela Mar 3, 2016
91eaefa
Merge pull request #91 from robertstephen/master
summerela Mar 3, 2016
73c1ffb
added updates for session 7
johnrudolph08 Mar 3, 2016
6320c29
Fix bug/typo
Mar 3, 2016
f7245d5
Moved Robert's Excel file into his dir
Mar 3, 2016
ca52457
Merge branch 'master' into rriehle-2016a-prep
Mar 3, 2016
a581b12
Adding HTML Rendering Part 2
summerrae78-cloud Mar 4, 2016
7aa128f
Updates
Mar 4, 2016
ff8ae39
Merge branch 'master' into rriehle-2016a-prep
Mar 4, 2016
d6b54bc
add slice lab1 project
tsegas Mar 4, 2016
2047411
add slice lab2 project
tsegas Mar 4, 2016
66d71aa
add slice lab3 project
tsegas Mar 4, 2016
7799dc1
add slice lab4 project
tsegas Mar 4, 2016
73429ca
add slice lab5 project
tsegas Mar 4, 2016
36f5c48
Pytalk files for this evening -ipynb warning changed inotebook LF to …
ThreeBbb Mar 4, 2016
de797e2
Merge branch 'master' of https://github.com/UWPCE-PythonCert/IntroPyt…
MikeSchincariol Mar 4, 2016
517ba45
Super considerd super
Mar 4, 2016
d6b8fb9
Session09 notebook
Mar 4, 2016
19a390e
Typos
Mar 4, 2016
969acfa
ClassMethods notebook
Mar 4, 2016
6fbdec3
Updated lightning talk schedule
Mar 4, 2016
00f1e4f
Pytalk files for this evening -ipynb warning changed inotebook LF to …
ThreeBbb Mar 6, 2016
4d005f5
Merge branch 'master' of git://github.com/ThreeBbb/IntroPython2016a i…
Mar 6, 2016
206db36
Merge branch 'master' of git://github.com/ThreeBbb/IntroPython2016a
Mar 6, 2016
51a0912
pushing session8 folder
johnrudolph08 Mar 7, 2016
0c13840
add list lab project
tsegas Mar 7, 2016
cb42249
add string formatting lab project
tsegas Mar 7, 2016
59ab989
Answer to D's question
Mar 8, 2016
fe24136
Merge branch 'rriehle-2016a-prep'
Mar 8, 2016
aad6936
Comments
Mar 8, 2016
c76ef15
Merge branch 'rriehle-2016a-prep'
Mar 8, 2016
2efb847
Typos
Mar 8, 2016
9cd547d
Merge branch 'rriehle-2016a-prep'
Mar 8, 2016
1a1a287
updated mailroom project
tsegas Mar 10, 2016
7ce64ae
Merge pull request #94 from tsegas/master
summerela Mar 10, 2016
f3fadad
Merge pull request #95 from johnrudolph08/master
summerela Mar 10, 2016
540462f
Merge pull request #92 from MikeSchincariol/master
summerela Mar 10, 2016
541abe2
attempting to add lightning talk materials
NewtonMD Mar 10, 2016
2f657cf
Adding Lambda Lab intro
summerrae78-cloud Mar 10, 2016
fb3a702
Luis's lightning talk
Mar 10, 2016
cecce9c
Updated lightning talk presenters, removed temporal reference
Mar 10, 2016
98394b8
Merge branch 'master' into rriehle-2016a-prep
Mar 10, 2016
22bfea4
Move assert into out of lecture and into exercise
Mar 10, 2016
77a204a
Session10 notebook
Mar 10, 2016
481f3f1
assert discussion
Mar 10, 2016
4dce4ad
Session10 notebook
Mar 11, 2016
96bd485
Link to Brandon's talk
Mar 11, 2016
12bc4d1
Merge branch 'master' into rriehle-2016a-prep
Mar 11, 2016
57040e4
Chi's talk
Mar 14, 2016
8c78c75
Merge pull request #99 from NewtonMD/master
rriehle Mar 15, 2016
2aca40e
removed student listings
PythonCHB Dec 29, 2017
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
26 changes: 0 additions & 26 deletions Examples/Session01/schedule.txt

This file was deleted.

26 changes: 0 additions & 26 deletions Examples/Session01/students.txt

This file was deleted.

3 changes: 3 additions & 0 deletions Examples/Session05/cigar_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
or False otherwise.
"""


def cigar_party(cigars, is_weekend):
pass
15 changes: 14 additions & 1 deletion Examples/Session05/codingbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,17 @@


def sleep_in(weekday, vacation):
return not (weekday and vacation)
if vacation is True:
return True
elif weekday is False:
return True
else:
return False


def sumdouble(a, b):
if a == b:
return (a + b) * 2
else:
return(a + b)

21 changes: 17 additions & 4 deletions Examples/Session05/test_codingbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,32 @@
"""

from codingbat import sleep_in
from codingbat import sumdouble


def test_false_false():
assert sleep_in(False, False)
assert sleep_in(False, False) is True


def test_true_false():
assert not (sleep_in(True, False))
assert not (sleep_in(True, False)) is True


def test_false_true():
assert sleep_in(False, True)
assert sleep_in(False, True) is True


def test_true_true():
assert sleep_in(True, True)
assert sleep_in(True, True) is True


def test_sumdouble1():
assert sumdouble(1, 2) == 3


def test_sumdouble2():
assert sumdouble(3, 2) == 5


def test_sumdouble3():
assert sumdouble(2, 2) == 8
240 changes: 240 additions & 0 deletions Examples/Session06/test_trapz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
#!/usr/bin/env python3

"""
test code for the trapezoidal rule exercise
"""
import pytest

from trapz import trapz, frange, quadratic, curry_quadratic

# need a function for testing approximate equality
import math
try:
from math import isclose
except ImportError: # only there in py3.5

def isclose(a, b, rel_tol=1e-09, abs_tol=0.0):
"""
Determine whether two floating point numbers are close in value.

rel_tol
maximum difference for being considered "close", relative to the
magnitude of the input values
abs_tol
maximum difference for being considered "close", regardless of the
magnitude of the input values

Return True if a is close in value to b, and False otherwise.

For the values to be considered close, the difference between them
must be smaller than at least one of the tolerances.

-inf, inf and NaN behave similarly to the IEEE 754 Standard. That
is, NaN is not close to anything, even itself. inf and -inf are
only close to themselves.
"""

if rel_tol < 0.0 or abs_tol < 0.0:
raise ValueError('error tolerances must be non-negative')

if a == b: # short-circuit exact equality
return True
if math.isinf(a) or math.isinf(b):
# This includes the case of two infinities of opposite sign, or
# one infinity and one finite number. Two infinities of opposite sign
# would otherwise have an infinite relative tolerance.
return False
diff = abs(b - a)
return (((diff <= abs(rel_tol * b)) and
(diff <= abs(rel_tol * a))) or
(diff <= abs_tol))


def test_is_close():
''' just to make sure '''
assert isclose(4.5, 4.5)
assert isclose(4.5, 4.499999999999999999)

assert not isclose(4.5, 4.6)
# of course, not comprehesive!


# you need to compute a bunch of evenly spaced numbers from a to b
# kind of like range() but for floating point numbers
# I did it as a separate function so I could test it
def test_frange():
'''
tests the floating point range function
'''
r = frange(10, 20, 100)
assert len(r) == 101
assert r[0] == 10
assert r[-1] == 20
assert r[1] == 10.1
assert r[-2] == 19.9


def test_simple_line():
''' a simple horizontal line at y = 5'''
def line(x):
return 5

assert trapz(line, 0, 10) == 50


def test_sloping_line():
''' a simple linear function '''
def line(x):
return 2 + 3*x

# I got 159.99999999999 rather than 160
# hence the need for isclose()
assert isclose(trapz(line, 2, 10), 160)
m, B = 3, 2
a, b = 0, 5
assert isclose(trapz(line, a, b), 1/2*m*(b**2 - a**2) + B*(b-a))

a, b = 5, 10
assert isclose(trapz(line, a, b), 1/2*m*(b**2 - a**2) + B*(b-a))

a, b = -10, 5
assert isclose(trapz(line, a, b), 1/2*m*(b**2 - a**2) + B*(b-a))


def test_sine():
# a sine curve from zero to pi -- should be 2
# with a hundred points, only correct to about 4 figures
assert isclose(trapz(math.sin, 0, math.pi), 2.0, rel_tol=1e-04)


def test_sine2():
# a sine curve from zero to 2pi -- should be 0.0
# need to set an absolute tolerance when comparing to zero
assert isclose(trapz(math.sin, 0, 2*math.pi), 0.0, abs_tol=1e-8)


# test the quadratic function itself
# this is pytest's way to test a bunch of input and output values
# it creates a separate test for each case.
@pytest.mark.parametrize(("x", "y"), [(0, 1),
(1, 3),
(2, 7),
(-2, 3)
])
def test_quadratic_1(x, y):
"""
one set of coefficients
"""
assert quadratic(x, A=1, B=1, C=1) == y


# this is a nifty trick to write multiple tests at once:
# this will generate a test for each tuple passed in:
# each tuple is an x, and the expected y result
# don't worry about that weird "@" just yet -- we'll get to that!
# (but it's called a "decorator" if you're curious)
@pytest.mark.parametrize(("x", "y"), [(0, 2),
(1, 3),
(2, 0),
(-2, -12)
])
def test_quadratic_2(x, y):
"""
different coefficients
"""
assert quadratic(x, A=-2, B=3, C=2) == y


def quad_solution(a, b, A, B, C):
"""
Analytical solution to the area under a quadratic
used for testing
"""
return A/3*(b**3 - a**3) + B/2*(b**2 - a**2) + C*(b - a)


def test_quadratic_trapz_1():
"""
simplest case -- horizontal line
"""
A, B, C = 0, 0, 5
a, b = 0, 10
assert trapz(quadratic, a, b, A=A, B=B, C=C) == quad_solution(a, b, A, B, C)


def test_quadratic_trapz_2():
"""
one case: A=-1/3, B=0, C=4
"""
A, B, C = -1/3, 0, 4
a, b = -2, 2
assert isclose(trapz(quadratic, a, b, A=A, B=B, C=C),
quad_solution(a, b, A, B, C),
rel_tol=1e-3) # not a great tolerance -- maybe should try more samples!


def test_quadratic_trapz_args_kwargs():
"""
Testing if you can pass a combination of positional and keyword arguments
one case: A=2, B=-4, C=3
"""
A, B, C = 2, -4, 3
a, b = -2, 2
assert isclose(trapz(quadratic, a, b, A, B, C=C),
quad_solution(a, b, A, B, C),
rel_tol=1e-3) # not a great tolerance -- maybe should try more samples!


def test_curry_quadratic():
# tests if the quadratic currying function

# create a specific quadratic function:
quad234 = curry_quadratic(2, 3, 4)
# quad234 is now a function that can take one argument, x
# and will evaluate quadratic for those particular values of A,B,C

# try it for a few values
for x in range(5):
assert quad234(x) == quadratic(x, 2, 3, 4)


def test_curry_quadratic_trapz():
# tests if the quadratic currying function

# create a specific quadratic function:
quad234 = curry_quadratic(-2, 2, 3)
# quad234 is now a function that can take one argument, x
# and will evaluate quadratic for those particular values of A,B,C

# try it with the trapz function
assert trapz(quad234, -5, 5) == trapz(quadratic, -5, 5, -2, 2, 3)


# testing the functools.partial version:
from trapz import quad_partial_123
def test_partial():
a = 4
b = 10
# quad_partial_123 is the quadratic function with A,B,C = 1,2,3
assert trapz(quad_partial_123, a, b) == trapz(quadratic, a, b, 1, 2, 3)


# testing trapz with another function with multiple parameters.
def sine_freq_amp(t, amp, freq):
"the sine function with a frequency and amplitude specified"
return amp * math.sin(freq * t)


def solution_freq_amp(a, b, amp, freq):
" the solution to the definite integral of the general sin function"
return amp / freq * (math.cos(freq * a) - math.cos(freq * b))


def test_sine_freq_amp():
a = 0
b = 5
omega = 0.5
amp = 10
assert isclose(trapz(sine_freq_amp, a, b, amp=amp, freq=omega),
solution_freq_amp(a, b, amp, omega),
rel_tol=1e-04)
File renamed without changes.
Loading