Skip to content

Commit

Permalink
added test_All.py implementation as a base to build tests for MIS mod…
Browse files Browse the repository at this point in the history
…ules
  • Loading branch information
niazim3 committed Jul 25, 2018
1 parent 73f2bb5 commit 03fdd1b
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions CaseStudies/glass/src/Python/NewImplementation/test_All.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import pytest
from CurveADT import *
from Data import *
from SeqServices import *

class TestAll:

@classmethod
def setup_class(cls):
""" setup any state specific to the execution of the given class (which
usually contains tests).
"""

@classmethod
def teardown_class(cls):
""" teardown any state that was previously setup with a call to
setup_class.
"""

def setup_method(self):
X = [1, 2, 10]
Y = [1, 2, 10]
o = 1
self.c1 = CurveT(X, Y, o)

X = [0, 5, 9, 13]
Y = [0, 3, 30, 27]
o = 2
self.c2 = CurveT(X, Y, o)

def teardown_method(self, method):
self.c1 = None
self.c2 = None

# test SeqServices.py

@staticmethod
def test_isAscending():
assert (isAscending([1, 2, 3, 4, 5.5]))
assert (not (isAscending([1, 2, 3, 4, 0])))
assert (not (isAscending([1, 2, 0, 4, 5])))

@staticmethod
def test_isInBounds():
A = [1, 2, 3, 4, 5.5]
assert (isInBounds(A, 3.4))
assert (not(isInBounds(A, 100)))
assert (not(isInBounds(A, 0)))

@staticmethod
def test_interpLin():
assert (interpLin(3 , 6 , 4.5 , 5.67 , 4) == 5.78)

@staticmethod
def test_interpQuad():
assert (interpQuad(0, 0, 3 , 6 , 4.5 , 5.67 , 4) == (5.8533333333333335))

@staticmethod
def test_index():
A = [1, 2, 3, 4, 5.5]
assert (index(A, 1) == 0) # x is present in list, checks "=" req
assert (index(A, 5.5) == 3) # ensures that x < A[i+1]
assert (index([1, 2, 3, 4, 5.5], 3.12345678) == 2) # i can be found easily

# test CurveADT.py

@staticmethod
def test_CurveT_ssmErr():
with pytest.raises(SeqSizeMismatch):
c = CurveT([0,1,2], [0], 1)
c = CurveT([0], [0,1,2], 2)

@staticmethod
def test_CurveT_notAscendingErr():
with pytest.raises(IndepVarNotAscending):
c = CurveT([0,0,0], [0, 1, 3], 1) # x values are equal
c = CurveT([5,4,6], [0, 1, 3], 2)

@staticmethod
def test_CurveT_InvalidInterpErr():
with pytest.raises(InvalidInterpOrder):
c = CurveT([1, 2, 3], [0, 1, 3], 0)
c = CurveT([1, 2, 3], [0, 1, 3], 3)

def test_CurveT_oodErr(self):
with pytest.raises(OutOfDomain):
e = self.c1.eval(100)
e = self.c1.dfdx(0)
e = self.c2.dfdx(100.607)

def test_minD(self):
assert (self.c1.minD() == 1)

def test_maxD(self):
assert (self.c1.maxD() == 10)

def test_order(self):
assert (self.c1.order() == 1)

def test_eval(self):
assert (self.c1.eval(3) == 3) # order 1 tested
assert (self.c2.eval(6) == 7.083333333333334) # order 2 tested

def test_dfdx(self):
assert (self.c1.dfdx(3) == 0.9999999999998899) # order 1 tested
assert (self.c2.dfdx(10) == 1.124062500004186) # order 2 tested

def test_d2fdx2(self):
assert (self.c1.d2fdx2(3) == 0) # order 1 tested
assert (self.c2.d2fdx2(7) == 1.4999999926601504) # order 2 tested

12 comments on commit 03fdd1b

@niazim3
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that this file is not yet fully-specific for the MIS implemented thus far and is not a complete test either (e.g. many cases can be added to SeqServices testing).

@smiths
Copy link
Owner

@smiths smiths commented on 03fdd1b Jul 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry about complete testing. Once the infrastructure is in place, we can add to it.

I see that you have a folder called NewImplementation. I would rather not fall into the trap of having the old and the new concurrently. Version control keeps track of the old content. We could simply tag the repo with the last version that holds the old implementation. If anyone wants to see the old version they could check it out using the tag.

Having said that, it might confuse things now for you to delete the old and replace it with the new. However, once the new has benefitted as much as possible from the old, please remove the old version and replace it with the new, and remove the reference to new.

@smiths
Copy link
Owner

@smiths smiths commented on 03fdd1b Jul 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to run your test cases on my machine without having to remember syntax. Can you please create a rule for make test.

@niazim3
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of commit 95e6694, make test runs the test cases.

@smiths
Copy link
Owner

@smiths smiths commented on 03fdd1b Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see make test being used. Most of the tests pass on my computer, but a few fail. Please take a quick look at the failed tests. (I'll attach them.) I only had a quick look, but it looks like the failed tests might be related to expected exceptions, or maybe unintended exceptions? If the exceptions are expected, I believe that pytest can test that the correct exception is raised, which cause the test case to pass.

If there is any work or discussion involved in sorting this out, please create an issue.

Output of make test:

============================= test session starts ==============================
platform darwin -- Python 3.6.4, pytest-3.4.0, py-1.5.2, pluggy-0.6.0
rootdir: /Users/smiths/Repos/caseStudies/CaseStudies/glass/src/Python, inifile:
plugins: cov-2.5.1
collected 26 items

NewImplementation/test_All.py ....F...............FF....                 [100%]

---------- coverage: platform darwin, python 3.6.4-final-0 -----------
Name                                Stmts   Miss  Cover
-------------------------------------------------------
NewImplementation/Constants.py         12      0   100%
NewImplementation/ContoursADT.py       38      7    82%
NewImplementation/Exceptions.py        30      7    77%
NewImplementation/FunctADT.py          35      1    97%
NewImplementation/GlassTypeADT.py      31      0   100%
NewImplementation/Input.py             81     53    35%
NewImplementation/SeqServices.py       17      0   100%
NewImplementation/ThicknessADT.py      35      1    97%
NewImplementation/test_All.py         245     57    77%
-------------------------------------------------------
TOTAL                                 524    126    76%


=================================== FAILURES ===================================
______________________________ TestAll.test_index ______________________________

    @staticmethod
    def test_index():
        A = [1, 2, 3, 4, 5.5]
        assert (index(A, 1) == 0) # x is present in list, checks "=" req
>       assert (index(A, 5.5) == 3) # ensures that x < A[i+1]
E       assert None == 3
E        +  where None = index([1, 2, 3, 4, 5.5], 5.5)

NewImplementation/test_All.py:67: AssertionError
______________________ TestInput.test_load_params_default ______________________

self = <test_All.TestInput object at 0x10bbf2240>

    def test_load_params_default(self):
        s = "NewImplementation\\TestFiles\\defaultInputFile.txt"
        default = Input()
>       default.load_params(s)

NewImplementation/test_All.py:210: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Input.Input object at 0x10bbf2198>
s = 'NewImplementation\\TestFiles\\defaultInputFile.txt'

    def load_params ( self, s ):
>       inputFile = open(s, "r")
E       FileNotFoundError: [Errno 2] No such file or directory: 'NewImplementation\\TestFiles\\defaultInputFile.txt'

NewImplementation/Input.py:38: FileNotFoundError
_________________________ TestInput.test_verify_params _________________________

self = <test_All.TestInput object at 0x10bcc6b00>

    def test_verify_params(self):
        path = "NewImplementation\\TestFiles\\"
        init = Input()
        with pytest.raises(ValueError):
>           init.load_params(path+"aNegative.txt")

NewImplementation/test_All.py:243: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Input.Input object at 0x10bcc6a90>
s = 'NewImplementation\\TestFiles\\aNegative.txt'

    def load_params ( self, s ):
>       inputFile = open(s, "r")
E       FileNotFoundError: [Errno 2] No such file or directory: 'NewImplementation\\TestFiles\\aNegative.txt'

NewImplementation/Input.py:38: FileNotFoundError
===================== 3 failed, 23 passed in 0.27 seconds ======================

@elwazana
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smiths Hello Dr. Smith, that is an issue we have been trying to figure out for the past week. @samm82 and @niazim3 tests pass, except for the first AssertionError, however, mine has been failing with the exact same errors as you just got.

We aren't sure why this is happening, but @szymczdm believes it has something to do with the configuration of python/pytest.

@smiths
Copy link
Owner

@smiths smiths commented on 03fdd1b Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't have a close look at the pytest messages. An answer to your question is not immediately obvious to me. Please create a new issue and include the summary of what is happening. Please include a summary of the differences between your set-up and that off @niazim3 and @samm82. This should include the versions of Python, pytest, OS, and anything else you can think of. We should also get @szymczdm to run make test to see what output he gets. You can ask @szymczdm to do this as part of the new issue.

@samm82
Copy link
Collaborator

@samm82 samm82 commented on 03fdd1b Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the AssertionError in 87766ae, so we don't need an issue for that.

@samm82
Copy link
Collaborator

@samm82 samm82 commented on 03fdd1b Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My make is clean (no errors), but @elwazana gets a fail every time a filepath is used (which after the previous commit is 8 times).

@smiths
Copy link
Owner

@smiths smiths commented on 03fdd1b Jul 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the make errors on my machine (in 0252f54) by changing the file names. This could have broken the tests for the Windows machines.

@elwazana
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smiths The changes you made have corrected my errors and seems to still work for windows machines.

@smiths
Copy link
Owner

@smiths smiths commented on 03fdd1b Jul 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good news!

Please sign in to comment.