-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test_All.py implementation as a base to build tests for MIS mod…
…ules
- Loading branch information
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
CaseStudies/glass/src/Python/NewImplementation/test_All.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
03fdd1b
There was a problem hiding this comment.
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).
03fdd1b
There was a problem hiding this comment.
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.
03fdd1b
There was a problem hiding this comment.
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.
03fdd1b
There was a problem hiding this comment.
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.03fdd1b
There was a problem hiding this comment.
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:
03fdd1b
There was a problem hiding this comment.
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.
03fdd1b
There was a problem hiding this comment.
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.03fdd1b
There was a problem hiding this comment.
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.03fdd1b
There was a problem hiding this comment.
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).03fdd1b
There was a problem hiding this comment.
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.
03fdd1b
There was a problem hiding this comment.
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.
03fdd1b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good news!