From e7f23316633e926afa825596d258e1ccca00b607 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Mon, 15 Jun 2020 15:01:18 -0500 Subject: [PATCH] correct n->th closes #3238 --- .../tests/racket/contract/helpers.rkt | 37 +++++++++++++++++++ .../collects/racket/contract/private/guts.rkt | 13 ++++--- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/pkgs/racket-test/tests/racket/contract/helpers.rkt b/pkgs/racket-test/tests/racket/contract/helpers.rkt index 7e1a234c97..e2a5edd493 100644 --- a/pkgs/racket-test/tests/racket/contract/helpers.rkt +++ b/pkgs/racket-test/tests/racket/contract/helpers.rkt @@ -125,3 +125,40 @@ (check-equal? (f 1 0 3 4) (list 1 0 3 4)) (check-equal? (f 0 2 3 4) (list 0 2 3 4)) (check-equal? (f 0 2 3 4) (list 0 2 3 4)) + +(check-equal? (n->th 0) "0th") +(check-equal? (n->th 1) "1st") +(check-equal? (n->th 2) "2nd") +(check-equal? (n->th 3) "3rd") +(check-equal? (n->th 4) "4th") +(check-equal? (n->th 5) "5th") +(check-equal? (n->th 10) "10th") +(check-equal? (n->th 11) "11th") +(check-equal? (n->th 12) "12th") +(check-equal? (n->th 13) "13th") +(check-equal? (n->th 14) "14th") +(check-equal? (n->th 15) "15th") +(check-equal? (n->th 20) "20th") +(check-equal? (n->th 21) "21st") +(check-equal? (n->th 22) "22nd") +(check-equal? (n->th 23) "23rd") +(check-equal? (n->th 24) "24th") +(check-equal? (n->th 25) "25th") +(check-equal? (n->th 100) "100th") +(check-equal? (n->th 101) "101st") +(check-equal? (n->th 102) "102nd") +(check-equal? (n->th 103) "103rd") +(check-equal? (n->th 104) "104th") +(check-equal? (n->th 105) "105th") +(check-equal? (n->th 110) "110th") +(check-equal? (n->th 111) "111th") +(check-equal? (n->th 112) "112th") +(check-equal? (n->th 113) "113th") +(check-equal? (n->th 114) "114th") +(check-equal? (n->th 115) "115th") +(check-equal? (n->th 120) "120th") +(check-equal? (n->th 121) "121st") +(check-equal? (n->th 122) "122nd") +(check-equal? (n->th 123) "123rd") +(check-equal? (n->th 124) "124th") +(check-equal? (n->th 125) "125th") diff --git a/racket/collects/racket/contract/private/guts.rkt b/racket/collects/racket/contract/private/guts.rkt index 892a55e0a7..b1030a277d 100644 --- a/racket/collects/racket/contract/private/guts.rkt +++ b/racket/collects/racket/contract/private/guts.rkt @@ -961,11 +961,14 @@ (define (n->th n) (string-append (number->string n) - (case (modulo n 10) - [(1) "st"] - [(2) "nd"] - [(3) "rd"] - [else "th"]))) + (case (remainder n 100) + [(11 12 13) "th"] + [else + (case (modulo n 10) + [(1) "st"] + [(2) "nd"] + [(3) "rd"] + [else "th"])]))) (define (nth-element-of/alloc n) (format "the ~a element of" (n->th n)))