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.

85 lines
1.5 KiB

  1. package idvalidator
  2. import (
  3. "testing"
  4. )
  5. // go test -v -cover -coverprofile=cover.out
  6. // go tool cover -func=cover.out
  7. // go tool cover -html=cover.out
  8. func TestIsValid(t *testing.T) {
  9. ids := [4]string{
  10. "440308199901101512",
  11. "610104620927690",
  12. "810000199408230021",
  13. "830000199201300022",
  14. }
  15. for _, id := range ids {
  16. if !IsValid(id) {
  17. t.Errorf("%s must be true.", id)
  18. }
  19. }
  20. errIds := [6]string{
  21. "440308199901101513",
  22. "4403081999011015133",
  23. "510104621927691",
  24. "61010462092769",
  25. "810000199408230022",
  26. "830000199201300023",
  27. }
  28. for _, id := range errIds {
  29. if IsValid(id) {
  30. t.Errorf("%s must be false.", id)
  31. }
  32. }
  33. }
  34. func TestGetInfo(t *testing.T) {
  35. _, err := GetInfo("440308199901101512")
  36. if err != nil {
  37. t.Errorf("Errors must be nil.")
  38. }
  39. _, e := GetInfo("440308199901101513")
  40. if e == nil {
  41. t.Errorf("Errors must not be nil.")
  42. }
  43. }
  44. func TestUpgradeId(t *testing.T) {
  45. _, err := UpgradeId("610104620927690")
  46. if err != nil {
  47. t.Errorf("Errors must be nil.")
  48. }
  49. _, e := UpgradeId("61010462092769")
  50. if e == nil {
  51. t.Errorf("Errors must not be nil.")
  52. }
  53. }
  54. func TestFakeId(t *testing.T) {
  55. id := FakeId()
  56. if len(id) != 18 {
  57. t.Errorf("String length must be 18. : %s", id)
  58. }
  59. if !IsValid(id) {
  60. t.Errorf("%s must be true.", id)
  61. }
  62. }
  63. func TestFakeRequireId(t *testing.T) {
  64. id := FakeRequireId(false, "", "", 0)
  65. if len(id) != 15 {
  66. t.Errorf("String length must be 15. : %s", id)
  67. }
  68. if !IsValid(id) {
  69. t.Errorf("%s must be true.", id)
  70. }
  71. info, _ := GetInfo(id)
  72. if info.Sex != 0 {
  73. t.Errorf("%s must be 0.", "0")
  74. }
  75. }