convert_versions_test.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-FileCopyrightText: Adam Evyčędo
  2. //
  3. // SPDX-License-Identifier: AGPL-3.0-or-later
  4. package traffic
  5. import (
  6. "testing"
  7. "time"
  8. )
  9. func TestFindValidVersionsDecember2023Poznan(t *testing.T) {
  10. timezone, _ := time.LoadLocation("Europe/Warsaw")
  11. validities := []Validity{
  12. "20231201_20231203",
  13. "20231202_20231222",
  14. "20231209_20231215",
  15. "20231214_20231215",
  16. "20231215_20231215",
  17. "20231216_20231222",
  18. "20231223_20231224",
  19. "20231225_20231225",
  20. "20231226_20231230",
  21. }
  22. allVersions := make([]Version, len(validities))
  23. var err error
  24. for i, validity := range validities {
  25. allVersions[i], err = MakeVersionTimezone(string(validity), timezone)
  26. if err != nil {
  27. t.Fatalf("MakeVersion errored on %s: %v\n", validity, err)
  28. }
  29. }
  30. validVersions := FindValidVersions(allVersions, time.Date(2023, time.December, 1, 4, 0, 0, 0, timezone))
  31. if len(validVersions) != 9 {
  32. t.Fatalf("wanted 9 elements, got %v\n", validVersions)
  33. }
  34. }
  35. func TestFindValidVersionsChristmasEve2023Poznan(t *testing.T) {
  36. timezone, _ := time.LoadLocation("Europe/Warsaw")
  37. validities := []Validity{
  38. "20231223_20231224",
  39. "20231225_20231225",
  40. "20231226_20231230",
  41. }
  42. allVersions := make([]Version, len(validities))
  43. var err error
  44. for i, validity := range validities {
  45. allVersions[i], err = MakeVersionTimezone(string(validity), timezone)
  46. if err != nil {
  47. t.Fatalf("MakeVersion errored on %s: %v\n", validity, err)
  48. }
  49. }
  50. validVersions := FindValidVersions(allVersions, time.Date(2023, time.December, 24, 4, 0, 0, 0, timezone))
  51. if len(validVersions) != 3 && validVersions[0].String() == "20231223_20231224" && validVersions[1].String() == "20231225_20231225" && validVersions[2].String() == "20231226_20231230" {
  52. t.Fatalf("wanted 3 elements, got %v\n", validVersions)
  53. }
  54. }
  55. func TestFindValidVersionsChristmasDay2023Poznan(t *testing.T) {
  56. timezone, _ := time.LoadLocation("Europe/Warsaw")
  57. validities := []Validity{
  58. "20231223_20231224",
  59. "20231225_20231225",
  60. "20231226_20231230",
  61. }
  62. allVersions := make([]Version, len(validities))
  63. var err error
  64. for i, validity := range validities {
  65. allVersions[i], err = MakeVersionTimezone(string(validity), timezone)
  66. if err != nil {
  67. t.Fatalf("MakeVersion errored on %s: %v\n", validity, err)
  68. }
  69. }
  70. validVersions := FindValidVersions(allVersions, time.Date(2023, time.December, 25, 4, 0, 0, 0, timezone))
  71. if len(validVersions) != 2 && validVersions[0].String() == "20231225_20231225" && validVersions[1].String() == "20231226_20231230" {
  72. t.Fatalf("wanted 2 elements, got %v\n", validVersions)
  73. }
  74. }
  75. func TestFindValidVersionsBoxingDay2023Poznan(t *testing.T) {
  76. timezone, _ := time.LoadLocation("Europe/Warsaw")
  77. validities := []Validity{
  78. "20231223_20231224",
  79. "20231225_20231225",
  80. "20231226_20231230",
  81. }
  82. allVersions := make([]Version, len(validities))
  83. var err error
  84. for i, validity := range validities {
  85. allVersions[i], err = MakeVersionTimezone(string(validity), timezone)
  86. if err != nil {
  87. t.Fatalf("MakeVersion errored on %s: %v\n", validity, err)
  88. }
  89. }
  90. validVersions := FindValidVersions(allVersions, time.Date(2023, time.December, 26, 4, 0, 0, 0, timezone))
  91. if len(validVersions) != 1 && validVersions[0].String() == "20231226_20231230" {
  92. t.Fatalf("wanted 1 elements, got %v\n", validVersions)
  93. }
  94. }
  95. func TestFindValidVersionsSingleDay(t *testing.T) {
  96. timezone, _ := time.LoadLocation("Europe/Warsaw")
  97. validities := []Validity{
  98. "20231225_20231225",
  99. }
  100. allVersions := make([]Version, len(validities))
  101. var err error
  102. for i, validity := range validities {
  103. allVersions[i], err = MakeVersionTimezone(string(validity), timezone)
  104. if err != nil {
  105. t.Fatalf("MakeVersion errored on %s: %v\n", validity, err)
  106. }
  107. }
  108. validVersions := FindValidVersions(allVersions, time.Date(2023, time.December, 25, 4, 0, 0, 0, timezone))
  109. if len(validVersions) != 1 && validVersions[0].String() == "20231225_20231225" {
  110. t.Fatalf("wanted 1 elements, got %v\n", validVersions)
  111. }
  112. }