factor.tests 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh
  2. # Copyright 2017 by Denys Vlasenko <vda.linux@googlemail.com>
  3. # Licensed under GPLv2, see file LICENSE in this source tree.
  4. . ./testing.sh
  5. # testing "test name" "command" "expected result" "file input" "stdin"
  6. # file input will be file called "input"
  7. # test can create a file "actual" instead of writing to stdout
  8. testing "factor ' 0'" \
  9. "factor ' 0'" \
  10. "0:\n" \
  11. "" ""
  12. testing "factor +1" \
  13. "factor +1" \
  14. "1:\n" \
  15. "" ""
  16. testing "factor ' +2'" \
  17. "factor ' +2'" \
  18. "2: 2\n" \
  19. "" ""
  20. testing "factor 1024" \
  21. "factor 1024" \
  22. "1024: 2 2 2 2 2 2 2 2 2 2\n" \
  23. "" ""
  24. testing "factor 2^61-1" \
  25. "factor 2305843009213693951" \
  26. "2305843009213693951: 2305843009213693951\n" \
  27. "" ""
  28. testing "factor 2^62-1" \
  29. "factor 4611686018427387903" \
  30. "4611686018427387903: 3 715827883 2147483647\n" \
  31. "" ""
  32. testing "factor 2^64-1" \
  33. "factor 18446744073709551615" \
  34. "18446744073709551615: 3 5 17 257 641 65537 6700417\n" \
  35. "" ""
  36. # This is a 60-bit number (0x888 86ff db34 4692): first few primes multiplied together:
  37. testing "factor \$((2*3*5*7*11*13*17*19*23*29*31*37*41*43*47))" \
  38. "factor \$((2*3*5*7*11*13*17*19*23*29*31*37*41*43*47))" \
  39. "614889782588491410: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47\n" \
  40. "" ""
  41. # Test that square-detection code is not buggy
  42. testing "factor 2 * 3037000493 * 3037000493" \
  43. "factor 18446743988964486098" \
  44. "18446743988964486098: 2 3037000493 3037000493\n" \
  45. "" ""
  46. testing "factor 3 * 2479700513 * 2479700513" \
  47. "factor 18446743902517389507" \
  48. "18446743902517389507: 3 2479700513 2479700513\n" \
  49. "" ""
  50. # including square-of-square cases:
  51. testing "factor 3 * 37831 * 37831 * 37831 * 37831" \
  52. "factor 6144867742934288163" \
  53. "6144867742934288163: 3 37831 37831 37831 37831\n" \
  54. "" ""
  55. testing "factor 3 * 13^16" \
  56. "factor 1996249827549539523" \
  57. "1996249827549539523: 3 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13\n" \
  58. "" ""
  59. testing "factor 13^16" \
  60. "factor 665416609183179841" \
  61. "665416609183179841: 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13\n" \
  62. "" ""
  63. exit $FAILCOUNT