Skip to content

Commit 46e7594

Browse files
expanded date addition test coverage and added optimized snapshot test
1 parent daab6fa commit 46e7594

File tree

3 files changed

+61822
-0
lines changed

3 files changed

+61822
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// This file is part of ICU4X. For terms of use, please see the file
2+
// called LICENSE at the top level of the ICU4X source tree
3+
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4+
5+
use icu_calendar::{AnyCalendar, AnyCalendarKind, Date};
6+
use std::fmt::Write;
7+
8+
#[test]
9+
fn test_generate_dates_and_durations_for_review() {
10+
let calendars = vec![
11+
AnyCalendarKind::Iso,
12+
AnyCalendarKind::Gregorian,
13+
AnyCalendarKind::Buddhist,
14+
AnyCalendarKind::Chinese,
15+
AnyCalendarKind::Coptic,
16+
AnyCalendarKind::Dangi,
17+
AnyCalendarKind::Ethiopian,
18+
AnyCalendarKind::EthiopianAmeteAlem,
19+
AnyCalendarKind::Hebrew,
20+
AnyCalendarKind::HijriSimulatedMecca,
21+
AnyCalendarKind::HijriTabularTypeIIFriday,
22+
AnyCalendarKind::HijriTabularTypeIIThursday,
23+
AnyCalendarKind::HijriUmmAlQura,
24+
AnyCalendarKind::Indian,
25+
AnyCalendarKind::Japanese,
26+
AnyCalendarKind::JapaneseExtended,
27+
AnyCalendarKind::Persian,
28+
AnyCalendarKind::Roc,
29+
];
30+
31+
32+
let iso_dates = vec![
33+
(2000, 1, 1),
34+
(2000, 2, 28),
35+
(2000, 2, 29),
36+
(2000, 3, 1),
37+
(2001, 2, 28),
38+
(2004, 2, 28),
39+
(2004, 2, 29),
40+
(2004, 3, 1),
41+
(2004, 12, 31),
42+
];
43+
44+
45+
let mut durations: Vec<(i32, i32, i32)> = Vec::new();
46+
47+
for d in -65..=65 {
48+
durations.push((0, 0, d));
49+
}
50+
51+
for m in -30..=30 {
52+
durations.push((0, m, 0));
53+
}
54+
55+
for md in -30..=30 {
56+
let day = if md < 0 { -1 } else if md == 0 { 0 } else { 1 };
57+
durations.push((0, md, day));
58+
}
59+
60+
for y in -10..=10 {
61+
durations.push((y, 0, 0));
62+
}
63+
64+
for ym in -10..=10 {
65+
let month = if ym < 0 { -1 } else if ym == 0 { 0 } else { 1 };
66+
durations.push((ym, month, 0));
67+
}
68+
69+
for yd in -10..=10 {
70+
let day = if yd < 0 { -1 } else if yd == 0 { 0 } else { 1 };
71+
durations.push((yd, 0, day));
72+
}
73+
74+
for ymd in -10..=10 {
75+
let (month, day) = if ymd < 0 { (-1, -1) } else if ymd == 0 { (0, 0) } else { (1, 1) };
76+
durations.push((ymd, month, day));
77+
}
78+
79+
80+
let mut output = String::new();
81+
82+
writeln!(&mut output, "Durations total: {}", durations.len()).unwrap();
83+
writeln!(&mut output).unwrap();
84+
85+
for cal_kind in &calendars {
86+
let cal = AnyCalendar::new(*cal_kind);
87+
writeln!(&mut output, "Calendar: {:?}", cal_kind).unwrap();
88+
89+
for (y, m, d) in &iso_dates {
90+
91+
let start_date = Date::try_new_iso(*y, *m, *d)
92+
.expect("Valid ISO date")
93+
.to_calendar(cal.clone());
94+
95+
writeln!(&mut output, " START: {:04}-{:02}-{:02} -> {:?}", y, m, d, start_date)
96+
.unwrap();
97+
98+
99+
let show_n = 8usize;
100+
for (i, dur) in durations.iter().enumerate() {
101+
if i < show_n || i + show_n >= durations.len() {
102+
writeln!(&mut output, " +{:>4}Y {:>4}M {:>4}D", dur.0, dur.1, dur.2).unwrap();
103+
} else if i == show_n {
104+
writeln!(&mut output, " ... {} omitted ...", durations.len() - (show_n * 2)).unwrap();
105+
}
106+
}
107+
108+
writeln!(&mut output).unwrap();
109+
}
110+
111+
writeln!(&mut output).unwrap();
112+
}
113+
114+
115+
assert!(!output.is_empty());
116+
117+
println!("{}", output);
118+
}

0 commit comments

Comments
 (0)