-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shakeb #11
base: master
Are you sure you want to change the base?
Shakeb #11
Changes from 3 commits
46c3f48
4f74997
8da0234
c7f91db
32cb0e3
794d950
5c800a5
48e5f9d
ec66cc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import unittest | ||
from optv.parameters import MultimediaParams, ShakingParams | ||
import numpy | ||
|
||
class Test_Parameters_binding(unittest.TestCase): | ||
def test_mm_np_instantiation(self): | ||
|
||
n2_np = numpy.array([11,22,33]) | ||
d_np = numpy.array([55,66,77]) | ||
|
||
m = MultimediaParams(nlay=3, n1=2, n2=n2_np, d=d_np, n3=4, lut=1) | ||
|
||
self.failUnlessEqual(m.get_nlay(), 3) | ||
self.failUnlessEqual(m.get_n1(), 2) | ||
self.failUnlessEqual(m.get_n3(), 4) | ||
self.failUnlessEqual(m.get_lut(), 1) | ||
|
||
numpy.testing.assert_array_equal(m.get_d(), d_np) | ||
numpy.testing.assert_array_equal(m.get_n2(), n2_np) | ||
|
||
self.failUnlessEqual(m.__str__(), "nlay=\t3 \nn1=\t2.0 \nn2=\t{11.0, 22.0, 33.0}" | ||
+ " \nd=\t{55.0, 66.0, 77.0} \nn3=\t4.0 \nlut=\t1 ") | ||
|
||
def test_shaking_par_instantiation(self): | ||
|
||
# manually assign values to ShakingParams object and check the assignments were made correctly | ||
sp1 = ShakingParams(222, 333, 444, 555) | ||
|
||
self.failUnlessEqual(sp1.get_seq_first(), 222) | ||
self.failUnlessEqual(sp1.get_seq_last(), 333) | ||
self.failUnlessEqual(sp1.get_max_shaking_points(), 444) | ||
self.failUnlessEqual(sp1.get_max_shaking_frames(), 555) | ||
|
||
# checking C read_shaking_par function | ||
# read shaking parameters from a file and | ||
# verify the parameters were read correctly according to contents of specified file | ||
sp1.read_shaking_par("/home/student/Desktop/Max_OpenPtv/" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded path makes the test fail for anyone but you. We said you'll make a special |
||
"liboptv/tests/testing_fodder/parameters/shaking.par") | ||
self.failUnlessEqual(sp1.get_seq_first(), 410000) | ||
self.failUnlessEqual(sp1.get_seq_last(), 411055) | ||
self.failUnlessEqual(sp1.get_max_shaking_points(), 100) | ||
self.failUnlessEqual(sp1.get_max_shaking_frames(), 3) | ||
|
||
# manually assigning values exactly like in the shaking parameters testing file | ||
# to another ShakingParams object | ||
sp2 = ShakingParams(410000, 411055, 100, 3) | ||
|
||
self.failUnlessEqual(sp2.get_seq_first(), 410000) | ||
self.failUnlessEqual(sp2.get_seq_last(), 411055) | ||
self.failUnlessEqual(sp2.get_max_shaking_points(), 100) | ||
self.failUnlessEqual(sp2.get_max_shaking_frames(), 3) | ||
|
||
# now we have two identical ShakingParams objects (sp1 and sp2) for comparison | ||
self.assertTrue(sp1==sp2) | ||
self.assertFalse(sp1!=sp2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between this line and the one before? Same for the following occurrence on lines 59-60. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comparison is performed through function defined in ShakingParams: def __richcmp__ (ShakingParams self, ShakingParams other, operator): The third parameter is integer value to indicate the operation performed: 2 for '=' , 3 for '!=' (you must refer to them separately). So in order to check the comparisons I must pass '==' as well as '!=' . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. This is not trivial, better add a comment explaining it. |
||
|
||
#change one attribute in sp2 and assert the results of equality comparison are now inverted | ||
sp2.set_max_shaking_frames(-999) | ||
self.assertFalse(sp1==sp2) | ||
self.assertTrue(sp1!=sp2) | ||
|
||
|
||
if __name__ == "__main__": | ||
#import sys;sys.argv = ['', 'Test.testName'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented-out code. |
||
unittest.main() |
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.
If we're going through the trouble of all the 'or's then we don't need a goto.
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 logic is: If one of 'fcanf's returns 0 then the parameter was not read and it is considered an error.
What do I miss here?
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.
Of course. My problem is not twith the or, it's with the goto. The goto is there to avoid nesting, but with the short-circuit 'or' you don't nest so much, so you can do a simple if/else.