2015-10-16 66 views
3

假設我有一個SML簽名ALPHA。但我也有多個結構/函子alpha1,alpha2等,我希望與ALPHA一起使用。我的問題是,如果我有一個結構在這些模塊之外執行單元測試,我將如何單獨測試ALPHA簽名而不必指定我正在使用的結構?具有多種結構的SML簽名

爲了把事情的角度,這裏是一些代碼:

signature ALPHA = 
sig 
    val func1 
    val func2 
end 


structure alpha1 :> ALPHA = 
struct 
    fun func1 = (* Implementation *) 
    fun func1 = (* Implementation *) 
end 

functor alpha2 (D: DATA) :> ALPHA = 
struct 
     fun func1 = D.x 
     fun func2 = D.y 
end 

(** Unit testing module **) 

structure Tester = 
struct 

     (** What test cases do I put here? **) 

end 

回答

1

你會做Tester算符采取結構簽名ALPHA作爲輸入。例如:

signature TESTSUITE = 
sig 
    val tests : bool list 
end 

functor AlphaTester (Alpha : ALPHA) :> TESTSUITE = 
struct 
    val func1_test_1 = Alpha.func1 ... = expected1 
    val func2_test_2 = Alpha.func2 ... = expected2 
    val tests = [ func1_test_1 
       , func2_test_1 ] 
end 

structure Alpha1Tester = AlphaTester(Alpha1) 
structure Alpha2Tester = AlphaTester(Alpha2(SomeD)) 
structure AllTests :> TESTSUITE = 
struct 
    val tests = AlphaTester1.tests @ AlphaTester2.tests 
end