Specs provides two different means of hierarchically structuring your specifications. One is by defining a "system under specification" and the other is by making sub-examples (one example is one specification/test statement).
Can someone please answer or point to a website what the intended usage of those different mechanisms is in general? I'm also curious about the reusing of specifications/examples.
My Use-Case
In particular I have a project that contains different algorithms A to compute some output X given a specific i开发者_StackOverflow社区nput examples Y. Should I choose the algorithms A to be the SUS, so that I can reuse a setup like "must compute the correct result for example Y_1; must compute the correct result for example Y_2; ..."? Or should I specify the different examples to be the SUS, so that I get "must be solvable by algorithm A_1; must be solvable by algorithm A_2; ..."?
What shall I turn into SUS and what into sub-examples?
Usually the system under specification (SUS) is the code that you're specifying, not the data.
Then the main differences between the SUS and normal examples/sub-examples in specs is the fact that a SUS has several additional methods to set the context such as the ->- method.
What I would actually suggest in your case, if the data is effectively the same for each algorithm is simply to define a method to create your examples:
def examplesMustPassFor(algo: Algorithm) = {
"The algo "+algo.name should {
"pass the data set 1" in { ... }
"pass the data set 2" in { ... }
"pass the data set 3" in { ... }
}
}
examplesMustPassFor(algo1)
examplesMustPassFor(algo2)
examplesMustPassFor(algo3)
Another important point that I want to mention is that the specs project has now been superseded by specs2 so you might want to check this one out if you're just starting writing your specifications.
Of course don't hesitate to ask more specific questions with code samples on the mailing-list if you want.
Eric.
精彩评论