BCD.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * BCD tests
  3. *
  4. * @author n1474335 [n1474335@gmail.com]
  5. * @copyright Crown Copyright 2017
  6. * @license Apache-2.0
  7. */
  8. import TestRegister from "../../TestRegister.js";
  9. TestRegister.addTests([
  10. {
  11. name: "To BCD: default 0",
  12. input: "0",
  13. expectedOutput: "0000",
  14. recipeConfig: [
  15. {
  16. "op": "To BCD",
  17. "args": ["8 4 2 1", true, false, "Nibbles"]
  18. }
  19. ]
  20. },
  21. {
  22. name: "To BCD: unpacked nibbles",
  23. input: "1234567890",
  24. expectedOutput: "0000 0001 0000 0010 0000 0011 0000 0100 0000 0101 0000 0110 0000 0111 0000 1000 0000 1001 0000 0000",
  25. recipeConfig: [
  26. {
  27. "op": "To BCD",
  28. "args": ["8 4 2 1", false, false, "Nibbles"]
  29. }
  30. ]
  31. },
  32. {
  33. name: "To BCD: packed, signed bytes",
  34. input: "1234567890",
  35. expectedOutput: "00000001 00100011 01000101 01100111 10001001 00001100",
  36. recipeConfig: [
  37. {
  38. "op": "To BCD",
  39. "args": ["8 4 2 1", true, true, "Bytes"]
  40. }
  41. ]
  42. },
  43. {
  44. name: "To BCD: packed, signed nibbles, 8 4 -2 -1",
  45. input: "-1234567890",
  46. expectedOutput: "0000 0111 0110 0101 0100 1011 1010 1001 1000 1111 0000 1101",
  47. recipeConfig: [
  48. {
  49. "op": "To BCD",
  50. "args": ["8 4 -2 -1", true, true, "Nibbles"]
  51. }
  52. ]
  53. },
  54. {
  55. name: "From BCD: default 0",
  56. input: "0000",
  57. expectedOutput: "0",
  58. recipeConfig: [
  59. {
  60. "op": "From BCD",
  61. "args": ["8 4 2 1", true, false, "Nibbles"]
  62. }
  63. ]
  64. },
  65. {
  66. name: "From BCD: packed, signed bytes",
  67. input: "00000001 00100011 01000101 01100111 10001001 00001101",
  68. expectedOutput: "-1234567890",
  69. recipeConfig: [
  70. {
  71. "op": "From BCD",
  72. "args": ["8 4 2 1", true, true, "Bytes"]
  73. }
  74. ]
  75. },
  76. {
  77. name: "From BCD: Excess-3, unpacked, unsigned",
  78. input: "00000100 00000101 00000110 00000111 00001000 00001001 00001010 00001011 00001100 00000011",
  79. expectedOutput: "1234567890",
  80. recipeConfig: [
  81. {
  82. "op": "From BCD",
  83. "args": ["Excess-3", false, false, "Nibbles"]
  84. }
  85. ]
  86. },
  87. {
  88. name: "BCD: raw 4 2 2 1, packed, signed",
  89. input: "1234567890",
  90. expectedOutput: "1234567890",
  91. recipeConfig: [
  92. {
  93. "op": "To BCD",
  94. "args": ["4 2 2 1", true, true, "Raw"]
  95. },
  96. {
  97. "op": "From BCD",
  98. "args": ["4 2 2 1", true, true, "Raw"]
  99. }
  100. ]
  101. },
  102. ]);