module term-common-test
imports libstratego-lib

strategies

  main =
    test-suite(!"term-common-test",
        get-constructor-tests
      ; get-arguments-tests
      ; get-appl-arguments-tests
      ; checksum-tests
    )

  get-constructor-tests = id
    ; apply-test(!"get-constructor 1"
      , get-constructor
      , !C()
      , !"C"
      )
    ; apply-test(!"get-constructor 2"
      , get-constructor
      , !B(1)
      , !"B"
      )
    ; apply-test(!"get-constructor 3"
      , get-constructor
      , !A(1, 2)
      , !"A"
      )

  get-arguments-tests = id
    ; apply-test(!"get-arguments 1"
      , get-arguments
      , !C()
      , ![]
      )
    ; apply-test(!"get-arguments 2"
      , get-arguments
      , !B(1)
      , ![1]
      )
    ; apply-test(!"get-arguments 3"
      , get-arguments
      , !A(1, 2)
      , ![1, 2]
      )

  get-appl-arguments-tests = id
    ; apply-test(!"get-appl-arguments 1"
      , get-appl-arguments
      , !C()
      , ![]
      )
    ; apply-test(!"get-appl-arguments 2"
      , get-appl-arguments
      , !B(1)
      , ![1]
      )
    ; apply-test(!"get-appl-arguments 3"
      , get-appl-arguments
      , !A(1, 2)
      , ![1, 2]
      )

    ; apply-test(!"get-appl-arguments 4"
      , get-appl-arguments(inc)
      , !C()
      , ![]
      )
    ; apply-test(!"get-appl-arguments 5"
      , get-appl-arguments(inc)
      , !B(1)
      , ![2]
      )
    ; apply-test(!"get-appl-arguments 6"
      , get-appl-arguments(inc)
      , !A(1, 2)
      , ![2, 3]
      )

  checksum-tests = id
    ; apply-test(!"checksum 1"
      , (checksum, checksum)
      , !(C(), C())
      , {x: ?(x, x) }
      )
    ; apply-test(!"checksum 2"
      , (checksum, checksum)
      , !(B(1),B(2))
      , {x,y: ?(x, y) ; not(!x => y) }
      )

signature
  constructors
    A : Int * Int -> A
    B : Int -> A
    C : A
