views:

56

answers:

1

Hello everybody,

i want to undertake some unit tests and a few functional tests on a working system. However i have a datastructure that mostly consists of a few arrays in an object (well its fortran, so not a real object, but you get the idea.) How would an example look like to unit test a datastructure? all examples i have seen so far returned a single value that was then tested. how do i do this with a datastructure that consists of arrays?

If i could get an example in funit, that would be great. Here is an example of my datastructure:

type :: myownobject
     integer :: front(300) 
     integer :: end(300)
     integer :: size
end type

   subroutine getmesugar(myob, moredata)
      type(myownobject), intent(inout) :: myob 
      integer, intent(in) :: moredata (20)
         ! do something with myownobject 
         ! perhaps add the data after a sanity check
         ! using the new data and the object

   end subroutine

i know its perhaps a simple question, but i am really just starting out with unit testing. i am reading The Art Of Unit Testing by Roy Osherove.

+1  A: 

Unit testing a data structure or, in more Fortranic terms, a derived data type, seems a rather vague notion. Perhaps what you want to do is test various uses of variables of derived type ?

The way you phrase your question also suggests that you may not have learned yet how to write functions which return arrays, or am I misinterpreting what you write ? You can also write functions which return derived data types.

Perhaps you could be more explicit about what you want to do with your type -- and that might suggest what unit tests you need to write.

EDIT: to answer OP's comments at a little more length than a comment allows ..

Long-term Fortran programmers, such as me, don't really know what a unit testing framework is. I remain to be convinced that any of the frameworks which have been published, such as fUnit, will have the longevity and portability of a pure Fortran approach. What are the chances that I will still be programming in Fortran in 10 years time -- quite high. What are the chances that I will be using a machine with a Ruby installation in 10 years time -- quite low. So my motivation for learning fUnit is low.

Yes, I write unit tests in Fortran. As to the testing of derived data types: I fail to see why you are having a problem with this. How do you unit test ? First you write down a set of inputs, and what outputs you expect your routine to produce if given those inputs. Then you execute the tests and compare what you get with what you expected to get. It's as simple as that. And the size and complexity of your derived data types doesn't alter the simplicity of the unit testing task, though it may make it more laborious without tool support.

If you are testing large data structures and have to read and write large volumes of data a tool such as Matlab becomes very useful -- you can very easily generate input data sets and compare actual and expected outputs both numerically and graphically.

High Performance Mark
well of course i want the functions that work on my derived data type to be unit tested. my subroutine works on the derived data type. i have changed the question so as to reflect that.
tarrasch
OK, now I really don't understand your question. Is it 'How can I use Funit to write and execute unit tests ?' ? On that subject I can't help, I write unit tests in Fortran.
High Performance Mark
ok, that means you have your own unit testing framework? all i want is to be sure that the function in the example above works as it should - which is the purpose of unit testing as i understood it. however the data that is processed cannot really be described by a simple data type, nor can the solution. So that means to test it i have to look at the datatype before and after the computation. My question is simply, how do i do this best? a proper testing harness like funit would be great, but i have no experiences so far with it
tarrasch
the thing is, if an experienced programmer like you uses his own testing framework, how is unit testing different from normal just looking if it works? I mean you always execute your code to see if it does what you want it to do. i am obviously new to this whole unit testing thing and i thought i could get better software by using it. now i fail to see whats different to what i did in my university studies.
tarrasch