github.com/richardwilkes/toolbox@v1.121.0/txt/roman_test.go (about)

     1  // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the Mozilla Public
     4  // License, version 2.0. If a copy of the MPL was not distributed with
     5  // this file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  //
     7  // This Source Code Form is "Incompatible With Secondary Licenses", as
     8  // defined by the Mozilla Public License, version 2.0.
     9  
    10  package txt_test
    11  
    12  import (
    13  	"testing"
    14  
    15  	"github.com/richardwilkes/toolbox/check"
    16  	"github.com/richardwilkes/toolbox/txt"
    17  )
    18  
    19  func TestToRoman(t *testing.T) {
    20  	type data struct {
    21  		e string
    22  		v int
    23  	}
    24  	for _, one := range []data{
    25  		{v: 1, e: "I"},
    26  		{v: 2, e: "II"},
    27  		{v: 3, e: "III"},
    28  		{v: 4, e: "IV"},
    29  		{v: 5, e: "V"},
    30  		{v: 6, e: "VI"},
    31  		{v: 7, e: "VII"},
    32  		{v: 8, e: "VIII"},
    33  		{v: 9, e: "IX"},
    34  		{v: 10, e: "X"},
    35  		{v: 11, e: "XI"},
    36  		{v: 14, e: "XIV"},
    37  		{v: 39, e: "XXXIX"},
    38  		{v: 40, e: "XL"},
    39  		{v: 41, e: "XLI"},
    40  		{v: 49, e: "XLIX"},
    41  		{v: 50, e: "L"},
    42  		{v: 51, e: "LI"},
    43  		{v: 89, e: "LXXXIX"},
    44  		{v: 90, e: "XC"},
    45  		{v: 99, e: "XCIX"},
    46  		{v: 100, e: "C"},
    47  		{v: 399, e: "CCCXCIX"},
    48  		{v: 400, e: "CD"},
    49  		{v: 499, e: "CDXCIX"},
    50  		{v: 500, e: "D"},
    51  		{v: 899, e: "DCCCXCIX"},
    52  		{v: 900, e: "CM"},
    53  		{v: 1967, e: "MCMLXVII"},
    54  		{v: 2021, e: "MMXXI"},
    55  	} {
    56  		check.Equal(t, one.e, txt.RomanNumerals(one.v), "input: %d", one.v)
    57  	}
    58  }