Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SML signature with multiple structures

Say I have an SML signature ALPHA. But I also have multiple structures/functors alpha1, alpha2, etc that I wish to use with ALPHA.

My question is this, if I were to have a struct that performs unit testing outside these modules, how would I solely test the ALPHA signature without having to specify which structure I am using?

To put things in perspective, here is some code:

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
like image 893
Fadhil Abubaker Avatar asked Feb 20 '26 00:02

Fadhil Abubaker


1 Answers

You would make Tester a functor taking a structure with signature ALPHA as input. For example:

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
like image 129
sshine Avatar answered Feb 21 '26 14:02

sshine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!