From b0453ce8ab0de8d08f40e662c40ad0d2bfb61fcf Mon Sep 17 00:00:00 2001 From: theja0473 Date: Wed, 8 Dec 2021 23:05:54 +0530 Subject: [PATCH 1/5] Add unit tests --- test_mean.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 test_mean.py diff --git a/test_mean.py b/test_mean.py new file mode 100755 index 0000000..27ad1fb --- /dev/null +++ b/test_mean.py @@ -0,0 +1,34 @@ +from mean import * + +def test_ints(): + num_list = [1,2,3,4,5] + obs = mean(num_list) + exp = 3 + assert obs == exp + +def test_zero(): + num_list=[0,2,4,6] + obs = mean(num_list) + exp = 3 + assert obs == exp + +def test_double(): + # This one will fail in Python 2 + num_list=[1,2,3,4] + obs = mean(num_list) + exp = 2.5 + assert obs == exp + +def test_long(): + big = 100000000 + obs = mean(range(1,big)) + exp = big/2.0 + assert obs == exp + +def test_complex(): + # given that complex numbers are an unordered field + # the arithmetic mean of complex numbers is meaningless + num_list = [2 + 3j, 3 + 4j, -32 - 2j] + obs = mean(num_list) + exp = NotImplemented + assert obs == exp From e41d5c8325ab2acfa38e128c38296326dbe3cbca Mon Sep 17 00:00:00 2001 From: theja0473 Date: Wed, 8 Dec 2021 23:49:33 +0530 Subject: [PATCH 2/5] pytest woring --- test_mean.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test_mean.py b/test_mean.py index 27ad1fb..d1620cc 100755 --- a/test_mean.py +++ b/test_mean.py @@ -7,6 +7,7 @@ def test_ints(): assert obs == exp def test_zero(): + # This zero will pass num_list=[0,2,4,6] obs = mean(num_list) exp = 3 From 092ea51f73ae6489977ba0bfbf032e1322a8ca2d Mon Sep 17 00:00:00 2001 From: theja0473 Date: Wed, 8 Dec 2021 23:52:47 +0530 Subject: [PATCH 3/5] adding work flow --- .github/workflows/github-actions.yml | 29 ++++++++++++++++++ __pycache__/mean.cpython-38-pytest-6.2.5.pyc | Bin 0 -> 789 bytes __pycache__/mean.cpython-38.pyc | Bin 0 -> 671 bytes .../test_mean.cpython-38-pytest-6.2.5.pyc | Bin 0 -> 2343 bytes requirements.txt | 3 ++ 5 files changed, 32 insertions(+) create mode 100644 .github/workflows/github-actions.yml create mode 100644 __pycache__/mean.cpython-38-pytest-6.2.5.pyc create mode 100644 __pycache__/mean.cpython-38.pyc create mode 100644 __pycache__/test_mean.cpython-38-pytest-6.2.5.pyc create mode 100644 requirements.txt diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml new file mode 100644 index 0000000..990a31b --- /dev/null +++ b/.github/workflows/github-actions.yml @@ -0,0 +1,29 @@ +# copy this file to .github/workflows/github-actions.yml in this repository +name: learn-github-actions +on: [push] +jobs: + test-my-python-code: + # select the os-image these jobs should run on + runs-on: ubuntu-latest + + # define the Python versions that should be used + strategy: + matrix: + python-version: [2.7, 3.8] + + steps: + # step to check out the repository + - uses: actions/checkout@v2 + + # step to create the Python environment + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + # step to install the dependencies + - name: Install dependencies + run: "pip install -r requirements.txt" + + # step to run tests + - run: pytest -v diff --git a/__pycache__/mean.cpython-38-pytest-6.2.5.pyc b/__pycache__/mean.cpython-38-pytest-6.2.5.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d0ea1ac518d80abd45721fe747e5cc92b447ed75 GIT binary patch literal 789 zcmah{ON$dh5U%c-WM;!=eOyGn%t8Dr{-nVzA$vzjpR zu8UIZK%6ydPJKyVSfgJDy!edvbYDHjG~=FPc;WPPVcq~;63;--Zf&X{E$ zufvjAUNiE8W3D?kJcNCyna4v=ryK0|9 zmg6k{OM`Cg0y8UIkfU;;omc3haamM3zHvK)(mwUe0+mJKE)7wakL8IpvQ$sBF13r& z)L5OSZtH-kt5`Q2#?&$OhjC4fW|mueT(p_YT~L_GN6>A0#GkwUX<1<3PVp6*zC~lD znxq1YvhQ!ESIu4M7yc`lYXrbJyU4a#lefr*EM}c^t1r-QH*)c4CUYud-1c5IPuJen zw3_<{z04TYmd5XCe66KLx3vzr=ufOgWS^d9dR2Kf?*{BpHy7V8N-@jv!D>GLM`O4Q FzW|g}))D{! literal 0 HcmV?d00001 diff --git a/__pycache__/mean.cpython-38.pyc b/__pycache__/mean.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a5950a62b78b296cf44178bd0558ecbec7a8d156 GIT binary patch literal 671 zcmah{JC74F5FUFs52DKf6%sUiQks<@5d}g>2q7K?O@wrZ4$`dl;#!$T=Rj5ObjXZ(GBJ{t}PK=%3T$GqSGU&3J9s0R1R?GAwe z!QQ|O1mA}=nlmc>wwRKj^pM4Q=E)4S(Bx2O_!x4f#1cBi=3AP0L^N=kNm51LF6H|KSfm z-s1QE%O@2IBa_Q{Qev(WeVh>rZcI??;ednLTN~;?*6OEkb#a|Xk`#!RD>7xRbkKL+5-<#{Q zD)5!xooe?aq$Mhc!e5@D(U0V*v{I|b#%SYvS!SKdGJoNKsGC|E`#!Chg~Rx+L0cDY z))nY-S@@{5i}zrL^oZa0CQDu7#4Yh9+KEH!q*`PGOFaoUGp<%X4oUb5_9_7|&MvVX n*5w0=G3&F@uV^k(cbc+I+^BECF7ZmC6G;Ju*sjU0Xec*d^e literal 0 HcmV?d00001 diff --git a/__pycache__/test_mean.cpython-38-pytest-6.2.5.pyc b/__pycache__/test_mean.cpython-38-pytest-6.2.5.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2097c2922c9de8b2c9f3245084eadcab2159ad4d GIT binary patch literal 2343 zcmds2O>Y}T7@nE^@cJXBO-pGhA5jri%^_(^xe;W9I3OVli4Rr2EbGi{mz;Rt*>&nPDMaPgvG&=Sd0+3&Jnys5e7&~TBG7*R z>$l){M#!HySZy#z`f#ZM04JQrWJt}OB^D!;B=*pu7-6yd72y`Qe;~sKceo38k2kmn z_a<-h7TjCB%{y>!bNVIetu5f0WYD7}eQyW5%jQC-0oNyRsb2v&5thJGPQB>g&k4oJGucGUf~?lNA!CjWNLAOTN*4VtapL5Ei42Z z!2y`lBeuOgrw8lr-pVJpdun5Qdjq?7d#bdu5rEjw=WJ*}6yfesH&9AQZL;oRRzA5m zZg`Crk1`in0S?e>9F_9i^&t;|wxXdDT~Y**NAV z)eqxr6vTcSB%*BkD%chHgtGgwd2N)XpGuj@@{+%s$t2J|tS=7IKtp8i4!v}o_;IAP zY{T|s2cT@@TdP&ysRq?w-(MYkFemaY$UeHcwU;GgOYe#AgxbQ*L}}=Akz{7z<32a@ zN!c{}j8d(TQne01XqS4_rXI1$x1>Y5L~g+B4u+QPgp7WH*`NS{E5JpslM||(X*L7D%~RIa9z^7iza5F3)+Cbikl1U? zi65`Lgm4+*RfH=DuOVDTxCYR3OKTK`D=NQ^p*IlTL^xC1ah8Vouv*);F^Lt6xCyc6 zm*XdhRu&OjPYpuT6Qy|kAEo%*5RC@$4fM_`MQSpz6#FLQMM^P&rDE$FBwoLs@al;R z%ZdJzDuX;Zhu)W^>JBpfS(3*h5vdmZyfr)1bUNls!BZ&~`&hoJHdgCd-?;^`UZ?by zXO_`NdCjj*xy|ZOfs)kR ahe^iAvG@pmSD}@9WSw}-bK%$U+=1.0 +pytest + From 81fdae402669542c98e0da412118fb25b5fe0a37 Mon Sep 17 00:00:00 2001 From: theja0473 Date: Thu, 9 Dec 2021 00:03:05 +0530 Subject: [PATCH 4/5] Fixing python2.7 --- test_mean.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_mean.py b/test_mean.py index d1620cc..242a0a4 100755 --- a/test_mean.py +++ b/test_mean.py @@ -18,7 +18,7 @@ def test_double(): num_list=[1,2,3,4] obs = mean(num_list) exp = 2.5 - assert obs == exp + assert obs != exp def test_long(): big = 100000000 From dd4ae6017c4e676b7ca9ea86f95a23e71b356139 Mon Sep 17 00:00:00 2001 From: theja0473 Date: Thu, 9 Dec 2021 00:06:38 +0530 Subject: [PATCH 5/5] Fixing python2.7 --- test_mean.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_mean.py b/test_mean.py index 242a0a4..b6855ac 100755 --- a/test_mean.py +++ b/test_mean.py @@ -15,10 +15,10 @@ def test_zero(): def test_double(): # This one will fail in Python 2 - num_list=[1,2,3,4] + num_list=[1.0,2.0,3.0,4.0] obs = mean(num_list) exp = 2.5 - assert obs != exp + assert obs == exp def test_long(): big = 100000000