Gets the name of a number, even if it's stupidly big. Supersedes TheoryOfNekomata/number-name.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

213 regels
5.7 KiB

  1. import getNumberName from '../../../index';
  2. describe('Ordinals', () => {
  3. describe('0 in hundreds place', () => {
  4. describe('0 in tens place', () => {
  5. describe.each`
  6. ones | onesName
  7. ${0} | ${'zeroth'}
  8. ${1} | ${'first'}
  9. ${2} | ${'second'}
  10. ${3} | ${'third'}
  11. ${4} | ${'fourth'}
  12. ${5} | ${'fifth'}
  13. ${6} | ${'sixth'}
  14. ${7} | ${'seventh'}
  15. ${8} | ${'eighth'}
  16. ${9} | ${'ninth'}
  17. `('$ones in ones place', ({
  18. ones,
  19. onesName,
  20. }) => {
  21. it(`converts ${ones} to ${onesName}`, () => {
  22. expect(getNumberName(ones, {ordinal: true})).toBe(onesName);
  23. });
  24. });
  25. });
  26. describe('1 in tens place', () => {
  27. describe.each`
  28. ones | onesName
  29. ${0} | ${'tenth'}
  30. ${1} | ${'eleventh'}
  31. ${2} | ${'twelfth'}
  32. ${3} | ${'thirteenth'}
  33. ${4} | ${'fourteenth'}
  34. ${5} | ${'fifteenth'}
  35. ${6} | ${'sixteenth'}
  36. ${7} | ${'seventeenth'}
  37. ${8} | ${'eighteenth'}
  38. ${9} | ${'nineteenth'}
  39. `('$ones in ones place', ({
  40. ones,
  41. onesName,
  42. }) => {
  43. it(`converts 1${ones} to ${onesName}`, () => {
  44. expect(getNumberName(10 + ones, {ordinal: true})).toBe(onesName);
  45. });
  46. });
  47. });
  48. describe.each`
  49. tens | tensName
  50. ${2} | ${'twenty'}
  51. ${3} | ${'thirty'}
  52. ${4} | ${'forty'}
  53. ${5} | ${'fifty'}
  54. ${6} | ${'sixty'}
  55. ${7} | ${'seventy'}
  56. ${8} | ${'eighty'}
  57. ${9} | ${'ninety'}
  58. `('$tens in tens place', ({tens, tensName}) => {
  59. describe('0 in ones place', () => {
  60. const value = (tens * 10);
  61. const name = tensName.replace(/y$/, 'ieth');
  62. it(`converts ${value} to ${name}`, () => {
  63. expect(getNumberName(value, {ordinal: true})).toBe(name);
  64. });
  65. });
  66. describe.each`
  67. ones | onesName
  68. ${1} | ${'first'}
  69. ${2} | ${'second'}
  70. ${3} | ${'third'}
  71. ${4} | ${'fourth'}
  72. ${5} | ${'fifth'}
  73. ${6} | ${'sixth'}
  74. ${7} | ${'seventh'}
  75. ${8} | ${'eighth'}
  76. ${9} | ${'ninth'}
  77. `('$ones in ones place', ({
  78. ones,
  79. onesName,
  80. }) => {
  81. const value = (tens * 10) + ones;
  82. const name = [tensName, onesName].join(' ').trim();
  83. it(`converts ${value} to ${name}`, () => {
  84. expect(getNumberName(value, {ordinal: true})).toBe(name);
  85. });
  86. });
  87. });
  88. });
  89. describe.each`
  90. hundreds | hundredsName
  91. ${1} | ${'one hundred'}
  92. ${2} | ${'two hundred'}
  93. ${3} | ${'three hundred'}
  94. ${4} | ${'four hundred'}
  95. ${5} | ${'five hundred'}
  96. ${6} | ${'six hundred'}
  97. ${7} | ${'seven hundred'}
  98. ${8} | ${'eight hundred'}
  99. ${9} | ${'nine hundred'}
  100. `('$hundreds in hundreds place', ({
  101. hundreds,
  102. hundredsName,
  103. }) => {
  104. describe('0 in tens place', () => {
  105. describe('0 in ones place', () => {
  106. const value = (hundreds * 100);
  107. const name = hundredsName + 'th';
  108. it(`converts ${value} to ${name}`, () => {
  109. expect(getNumberName(value, {ordinal: true})).toBe(name);
  110. });
  111. });
  112. describe.each`
  113. ones | onesName
  114. ${1} | ${'first'}
  115. ${2} | ${'second'}
  116. ${3} | ${'third'}
  117. ${4} | ${'fourth'}
  118. ${5} | ${'fifth'}
  119. ${6} | ${'sixth'}
  120. ${7} | ${'seventh'}
  121. ${8} | ${'eighth'}
  122. ${9} | ${'ninth'}
  123. `('$ones in ones place', ({
  124. ones,
  125. onesName,
  126. }) => {
  127. const value = (hundreds * 100) + ones;
  128. const name = [hundredsName, onesName].join(' ').trim();
  129. it(`converts ${value} to ${name}`, () => {
  130. expect(getNumberName(value, {ordinal: true})).toBe(name);
  131. });
  132. });
  133. });
  134. describe('1 in tens place', () => {
  135. describe.each`
  136. ones | onesName
  137. ${0} | ${'tenth'}
  138. ${1} | ${'eleventh'}
  139. ${2} | ${'twelfth'}
  140. ${3} | ${'thirteenth'}
  141. ${4} | ${'fourteenth'}
  142. ${5} | ${'fifteenth'}
  143. ${6} | ${'sixteenth'}
  144. ${7} | ${'seventeenth'}
  145. ${8} | ${'eighteenth'}
  146. ${9} | ${'nineteenth'}
  147. `('$ones in ones place', ({
  148. ones,
  149. onesName,
  150. }) => {
  151. const value = (hundreds * 100) + 10 + ones;
  152. const name = [hundredsName, onesName].join(' ').trim();
  153. it(`converts ${value} to ${name}`, () => {
  154. expect(getNumberName(value, {ordinal: true})).toBe(name);
  155. });
  156. });
  157. });
  158. describe.each`
  159. tens | tensName
  160. ${2} | ${'twenty'}
  161. ${3} | ${'thirty'}
  162. ${4} | ${'forty'}
  163. ${5} | ${'fifty'}
  164. ${6} | ${'sixty'}
  165. ${7} | ${'seventy'}
  166. ${8} | ${'eighty'}
  167. ${9} | ${'ninety'}
  168. `('$tens in tens place', ({tens, tensName}) => {
  169. describe('0 in ones place', () => {
  170. const value = (hundreds * 100) + (tens * 10);
  171. const name = [hundredsName, tensName.replace(/y$/, 'ieth')].join(' ').trim();
  172. it(`converts ${value} to ${name}`, () => {
  173. expect(getNumberName(value, {ordinal: true})).toBe(name);
  174. });
  175. });
  176. describe.each`
  177. ones | onesName
  178. ${1} | ${'first'}
  179. ${2} | ${'second'}
  180. ${3} | ${'third'}
  181. ${4} | ${'fourth'}
  182. ${5} | ${'fifth'}
  183. ${6} | ${'sixth'}
  184. ${7} | ${'seventh'}
  185. ${8} | ${'eighth'}
  186. ${9} | ${'ninth'}
  187. `('$ones in ones place', ({
  188. ones,
  189. onesName,
  190. }) => {
  191. const value = (hundreds * 100) + (tens * 10) + ones;
  192. const name = [hundredsName, tensName, onesName].join(' ').trim();
  193. it(`converts ${value} to ${name}`, () => {
  194. expect(getNumberName(value, {ordinal: true})).toBe(name);
  195. });
  196. });
  197. });
  198. });
  199. });