typed-racket/typed-racket-test/unit-tests/subst-tests.rkt
Andrew Kent 81b134cbb9 add refinement types, linear expr objs, and ineq props (#510)
This PR adds about half of the needed primitives and logic for
reasoning about linear integer arithmetic in programs with interesting
dependent types. Things have been added in a way s.t. programs will
still continue to typecheck as they did, but if you want integer literals
and certain operations (e.g. *,+,<,<=,=,>=,>) to include linear inequality
information by default, you need to include the
'#:with-linear-integer-arithmetic' keyword at the top of your module.

The other features needed to get TR to be able to check things like
verified vector operations will be to ajust function types so
dependencies can exist between arguments and a minor tweak to get
type inference to consider the symbolic objects of functions arguments.
These features should be coming shortly in a future pull request.
2017-03-27 14:32:29 -04:00

38 lines
1.6 KiB
Racket

#lang racket/base
(require "test-utils.rkt"
(rep type-rep)
(types utils abbrev numeric-tower substitute)
rackunit)
(provide tests)
(gen-test-main)
(define-syntax-rule (s img var tgt result)
(test-equal? (format "~a" '(img tgt))
(substitute img 'var tgt)
result))
(define-syntax-rule (s* imgs rest var tgt result)
(test-equal? (format "~a" '(img tgt))
(substitute-dots (list . imgs) rest 'var tgt)
result))
(define-syntax-rule (s... imgs var tgt result)
(test-equal? (format "~a" '(img tgt))
(substitute-dots (list . imgs) #f 'var tgt)
result))
(define tests
(test-suite "Tests for type substitution"
(s -Number a (-v a) -Number)
(s -Number a (-pair (-v a) -String) (-pair -Number -String))
(s -Number a (-pair -String (-v a)) (-pair -String -Number))
(s* (-Symbol -String) #f a (make-ListDots (-v a) 'a) (-lst* -Symbol -String))
(s* (-Symbol -String) Univ a (make-ListDots (-v a) 'a) (-lst* -Symbol -String #:tail (-lst Univ)))
(s... (-Number -Boolean) a (make-Function (list (make-arr-dots null -Number (-v a) 'a))) (-Number -Boolean . -> . -Number))
(s... (-Number -Boolean) a (make-Function (list (make-arr-dots (list -String) -Number (-v a) 'a))) (-String -Number -Boolean . -> . -Number))
(s... (-Number -Boolean) a (make-Function (list (make-arr-dots (list -String) -Number (-v b) 'a))) (-String (-v b) (-v b) . -> . -Number))
(s... (-Number -Boolean) a (make-Function (list (make-arr-dots (list -String) -Number (-v b) 'b)))
(make-Function (list (make-arr-dots (list -String) -Number (-v b) 'b))))))