pluralrules_test.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2013 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.i18n.pluralRulesTest');
  15. goog.setTestOnly('goog.i18n.pluralRulesTest');
  16. goog.require('goog.i18n.pluralRules');
  17. goog.require('goog.testing.jsunit');
  18. /** @suppress {missingRequire} */
  19. var Keyword = goog.i18n.pluralRules.Keyword;
  20. function testSimpleSelectEn() {
  21. var funcSelect = goog.i18n.pluralRules.enSelect_;
  22. assertEquals(Keyword.OTHER, funcSelect(0)); // 0 dollars
  23. assertEquals(Keyword.ONE, funcSelect(1)); // 1 dollar
  24. assertEquals(Keyword.OTHER, funcSelect(2)); // 2 dollars
  25. assertEquals(Keyword.OTHER, funcSelect(0, 2)); // 0.00 dollars
  26. assertEquals(Keyword.OTHER, funcSelect(1, 2)); // 1.00 dollars
  27. assertEquals(Keyword.OTHER, funcSelect(2, 2)); // 2.00 dollars
  28. }
  29. function testSimpleSelectRo() {
  30. var funcSelect = goog.i18n.pluralRules.roSelect_;
  31. assertEquals(Keyword.FEW, funcSelect(0)); // 0 dolari
  32. assertEquals(Keyword.ONE, funcSelect(1)); // 1 dolar
  33. assertEquals(Keyword.FEW, funcSelect(2)); // 2 dolari
  34. assertEquals(Keyword.FEW, funcSelect(12)); // 12 dolari
  35. assertEquals(Keyword.OTHER, funcSelect(23)); // 23 de dolari
  36. assertEquals(Keyword.FEW, funcSelect(1212)); // 1212 dolari
  37. assertEquals(Keyword.OTHER, funcSelect(1223)); // 1223 de dolari
  38. assertEquals(Keyword.FEW, funcSelect(0, 2)); // 0.00 dolari
  39. assertEquals(Keyword.FEW, funcSelect(1, 2)); // 1.00 dolari
  40. assertEquals(Keyword.FEW, funcSelect(2, 2)); // 2.00 dolari
  41. assertEquals(Keyword.FEW, funcSelect(12, 2)); // 12.00 dolari
  42. assertEquals(Keyword.FEW, funcSelect(23, 2)); // 23.00 dolari
  43. assertEquals(Keyword.FEW, funcSelect(1212, 2)); // 1212.00 dolari
  44. assertEquals(Keyword.FEW, funcSelect(1223, 2)); // 1223.00 dolari
  45. }
  46. function testSimpleSelectSr() {
  47. var funcSelect = goog.i18n.pluralRules.srSelect_; // Serbian
  48. assertEquals(Keyword.ONE, funcSelect(1));
  49. assertEquals(Keyword.ONE, funcSelect(31));
  50. assertEquals(Keyword.ONE, funcSelect(0.1));
  51. assertEquals(Keyword.ONE, funcSelect(1.1));
  52. assertEquals(Keyword.ONE, funcSelect(2.1));
  53. assertEquals(Keyword.FEW, funcSelect(3));
  54. assertEquals(Keyword.FEW, funcSelect(33));
  55. assertEquals(Keyword.FEW, funcSelect(0.2));
  56. assertEquals(Keyword.FEW, funcSelect(0.3));
  57. assertEquals(Keyword.FEW, funcSelect(0.4));
  58. assertEquals(Keyword.FEW, funcSelect(2.2));
  59. assertEquals(Keyword.OTHER, funcSelect(2.11));
  60. assertEquals(Keyword.OTHER, funcSelect(2.12));
  61. assertEquals(Keyword.OTHER, funcSelect(2.13));
  62. assertEquals(Keyword.OTHER, funcSelect(2.14));
  63. assertEquals(Keyword.OTHER, funcSelect(2.15));
  64. assertEquals(Keyword.OTHER, funcSelect(0));
  65. assertEquals(Keyword.OTHER, funcSelect(5));
  66. assertEquals(Keyword.OTHER, funcSelect(10));
  67. assertEquals(Keyword.OTHER, funcSelect(35));
  68. assertEquals(Keyword.OTHER, funcSelect(37));
  69. assertEquals(Keyword.OTHER, funcSelect(40));
  70. assertEquals(Keyword.OTHER, funcSelect(0.0, 1));
  71. assertEquals(Keyword.OTHER, funcSelect(0.5));
  72. assertEquals(Keyword.OTHER, funcSelect(0.6));
  73. assertEquals(Keyword.FEW, funcSelect(2));
  74. assertEquals(Keyword.ONE, funcSelect(2.1));
  75. assertEquals(Keyword.FEW, funcSelect(2.2));
  76. assertEquals(Keyword.FEW, funcSelect(2.3));
  77. assertEquals(Keyword.FEW, funcSelect(2.4));
  78. assertEquals(Keyword.OTHER, funcSelect(2.5));
  79. assertEquals(Keyword.OTHER, funcSelect(20));
  80. assertEquals(Keyword.ONE, funcSelect(21));
  81. assertEquals(Keyword.FEW, funcSelect(22));
  82. assertEquals(Keyword.FEW, funcSelect(23));
  83. assertEquals(Keyword.FEW, funcSelect(24));
  84. assertEquals(Keyword.OTHER, funcSelect(25));
  85. }