Skip to content

Commit 1b3b5f9

Browse files
committed
more tests
1 parent d73e094 commit 1b3b5f9

File tree

2 files changed

+362
-0
lines changed

2 files changed

+362
-0
lines changed

crates/core/src/models/data/submodels/period_anno.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,28 @@ mod tests {
9898
);
9999
assert_eq!(late.elapsed_periods_since(&early), 3); // whole of january (2) + half of december (1)
100100
}
101+
102+
#[test]
103+
fn test_to_date_end_of_period_year_and_month() {
104+
let period = Sut::YearAndMonth(YearAndMonth::december(2024));
105+
assert_eq!(
106+
period.to_date_end_of_period(),
107+
Date::from_str("2024-12-31").unwrap()
108+
);
109+
}
110+
111+
#[test]
112+
fn test_to_date_end_of_period_year_and_fortnight() {
113+
let period = Sut::YearMonthAndFortnight(
114+
YearMonthAndFortnight::builder()
115+
.year(2024.into())
116+
.month(Month::December)
117+
.half(MonthHalf::First)
118+
.build(),
119+
);
120+
assert_eq!(
121+
period.to_date_end_of_period(),
122+
Date::from_str("2024-12-15").unwrap()
123+
);
124+
}
101125
}

crates/core/src/models/data/submodels/year_month_and_fortnight.rs

Lines changed: 338 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,342 @@ mod tests {
322322
.build();
323323
assert_eq!(late.elapsed_periods_since(early), 25);
324324
}
325+
326+
#[test]
327+
fn to_date_end_of_period_january_first_half() {
328+
let sut = Sut::builder()
329+
.year(2025.into())
330+
.month(Month::January)
331+
.half(MonthHalf::First)
332+
.build();
333+
assert_eq!(
334+
sut.to_date_end_of_period(),
335+
Date::from_str("2025-01-15").unwrap()
336+
);
337+
}
338+
339+
#[test]
340+
fn to_date_end_of_period_january_second_half() {
341+
let sut = Sut::builder()
342+
.year(2025.into())
343+
.month(Month::January)
344+
.half(MonthHalf::Second)
345+
.build();
346+
assert_eq!(
347+
sut.to_date_end_of_period(),
348+
Date::from_str("2025-01-31").unwrap()
349+
);
350+
}
351+
352+
#[test]
353+
fn to_date_end_of_period_non_leap_year_february_first_half() {
354+
let sut = Sut::builder()
355+
.year(2025.into())
356+
.month(Month::February)
357+
.half(MonthHalf::First)
358+
.build();
359+
assert_eq!(
360+
sut.to_date_end_of_period(),
361+
Date::from_str("2025-02-14").unwrap()
362+
);
363+
}
364+
365+
#[test]
366+
fn to_date_end_of_period_non_leap_year_february_second_half() {
367+
let sut = Sut::builder()
368+
.year(2025.into())
369+
.month(Month::February)
370+
.half(MonthHalf::Second)
371+
.build();
372+
assert_eq!(
373+
sut.to_date_end_of_period(),
374+
Date::from_str("2025-02-28").unwrap()
375+
);
376+
}
377+
378+
#[test]
379+
fn to_date_end_of_period_leap_year_february_first_half() {
380+
let sut = Sut::builder()
381+
.year(2028.into())
382+
.month(Month::February)
383+
.half(MonthHalf::First)
384+
.build();
385+
assert_eq!(
386+
sut.to_date_end_of_period(),
387+
Date::from_str("2028-02-14").unwrap()
388+
);
389+
}
390+
391+
#[test]
392+
fn to_date_end_of_period_leap_year_february_second_half() {
393+
let sut = Sut::builder()
394+
.year(2028.into())
395+
.month(Month::February)
396+
.half(MonthHalf::Second)
397+
.build();
398+
assert_eq!(
399+
sut.to_date_end_of_period(),
400+
Date::from_str("2028-02-29").unwrap()
401+
);
402+
}
403+
404+
#[test]
405+
fn to_date_end_of_period_march_first_half() {
406+
let sut = Sut::builder()
407+
.year(2025.into())
408+
.month(Month::March)
409+
.half(MonthHalf::First)
410+
.build();
411+
assert_eq!(
412+
sut.to_date_end_of_period(),
413+
Date::from_str("2025-03-15").unwrap()
414+
);
415+
}
416+
417+
#[test]
418+
fn to_date_end_of_period_march_second_half() {
419+
let sut = Sut::builder()
420+
.year(2025.into())
421+
.month(Month::March)
422+
.half(MonthHalf::Second)
423+
.build();
424+
assert_eq!(
425+
sut.to_date_end_of_period(),
426+
Date::from_str("2025-03-31").unwrap()
427+
);
428+
}
429+
430+
#[test]
431+
fn to_date_end_of_period_april_first_half() {
432+
let sut = Sut::builder()
433+
.year(2025.into())
434+
.month(Month::April)
435+
.half(MonthHalf::First)
436+
.build();
437+
assert_eq!(
438+
sut.to_date_end_of_period(),
439+
Date::from_str("2025-04-15").unwrap()
440+
);
441+
}
442+
443+
#[test]
444+
fn to_date_end_of_period_april_second_half() {
445+
let sut = Sut::builder()
446+
.year(2025.into())
447+
.month(Month::April)
448+
.half(MonthHalf::Second)
449+
.build();
450+
assert_eq!(
451+
sut.to_date_end_of_period(),
452+
Date::from_str("2025-04-30").unwrap()
453+
);
454+
}
455+
456+
#[test]
457+
fn to_date_end_of_period_may_first_half() {
458+
let sut = Sut::builder()
459+
.year(2025.into())
460+
.month(Month::May)
461+
.half(MonthHalf::First)
462+
.build();
463+
assert_eq!(
464+
sut.to_date_end_of_period(),
465+
Date::from_str("2025-05-15").unwrap()
466+
);
467+
}
468+
469+
#[test]
470+
fn to_date_end_of_period_may_second_half() {
471+
let sut = Sut::builder()
472+
.year(2025.into())
473+
.month(Month::May)
474+
.half(MonthHalf::Second)
475+
.build();
476+
assert_eq!(
477+
sut.to_date_end_of_period(),
478+
Date::from_str("2025-05-31").unwrap()
479+
);
480+
}
481+
482+
#[test]
483+
fn to_date_end_of_period_june_first_half() {
484+
let sut = Sut::builder()
485+
.year(2025.into())
486+
.month(Month::June)
487+
.half(MonthHalf::First)
488+
.build();
489+
assert_eq!(
490+
sut.to_date_end_of_period(),
491+
Date::from_str("2025-06-15").unwrap()
492+
);
493+
}
494+
495+
#[test]
496+
fn to_date_end_of_period_june_second_half() {
497+
let sut = Sut::builder()
498+
.year(2025.into())
499+
.month(Month::June)
500+
.half(MonthHalf::Second)
501+
.build();
502+
assert_eq!(
503+
sut.to_date_end_of_period(),
504+
Date::from_str("2025-06-30").unwrap()
505+
);
506+
}
507+
508+
#[test]
509+
fn to_date_end_of_period_july_first_half() {
510+
let sut = Sut::builder()
511+
.year(2025.into())
512+
.month(Month::July)
513+
.half(MonthHalf::First)
514+
.build();
515+
assert_eq!(
516+
sut.to_date_end_of_period(),
517+
Date::from_str("2025-07-15").unwrap()
518+
);
519+
}
520+
521+
#[test]
522+
fn to_date_end_of_period_july_second_half() {
523+
let sut = Sut::builder()
524+
.year(2025.into())
525+
.month(Month::July)
526+
.half(MonthHalf::Second)
527+
.build();
528+
assert_eq!(
529+
sut.to_date_end_of_period(),
530+
Date::from_str("2025-07-31").unwrap()
531+
);
532+
}
533+
534+
#[test]
535+
fn to_date_end_of_period_august_first_half() {
536+
let sut = Sut::builder()
537+
.year(2025.into())
538+
.month(Month::August)
539+
.half(MonthHalf::First)
540+
.build();
541+
assert_eq!(
542+
sut.to_date_end_of_period(),
543+
Date::from_str("2025-08-15").unwrap()
544+
);
545+
}
546+
547+
#[test]
548+
fn to_date_end_of_period_august_second_half() {
549+
let sut = Sut::builder()
550+
.year(2025.into())
551+
.month(Month::August)
552+
.half(MonthHalf::Second)
553+
.build();
554+
assert_eq!(
555+
sut.to_date_end_of_period(),
556+
Date::from_str("2025-08-31").unwrap()
557+
);
558+
}
559+
560+
#[test]
561+
fn to_date_end_of_period_september_first_half() {
562+
let sut = Sut::builder()
563+
.year(2025.into())
564+
.month(Month::September)
565+
.half(MonthHalf::First)
566+
.build();
567+
assert_eq!(
568+
sut.to_date_end_of_period(),
569+
Date::from_str("2025-09-15").unwrap()
570+
);
571+
}
572+
573+
#[test]
574+
fn to_date_end_of_period_september_second_half() {
575+
let sut = Sut::builder()
576+
.year(2025.into())
577+
.month(Month::September)
578+
.half(MonthHalf::Second)
579+
.build();
580+
assert_eq!(
581+
sut.to_date_end_of_period(),
582+
Date::from_str("2025-09-30").unwrap()
583+
);
584+
}
585+
586+
#[test]
587+
fn to_date_end_of_period_october_first_half() {
588+
let sut = Sut::builder()
589+
.year(2025.into())
590+
.month(Month::October)
591+
.half(MonthHalf::First)
592+
.build();
593+
assert_eq!(
594+
sut.to_date_end_of_period(),
595+
Date::from_str("2025-10-15").unwrap()
596+
);
597+
}
598+
599+
#[test]
600+
fn to_date_end_of_period_october_second_half() {
601+
let sut = Sut::builder()
602+
.year(2025.into())
603+
.month(Month::October)
604+
.half(MonthHalf::Second)
605+
.build();
606+
assert_eq!(
607+
sut.to_date_end_of_period(),
608+
Date::from_str("2025-10-31").unwrap()
609+
);
610+
}
611+
612+
#[test]
613+
fn to_date_end_of_period_november_first_half() {
614+
let sut = Sut::builder()
615+
.year(2025.into())
616+
.month(Month::November)
617+
.half(MonthHalf::First)
618+
.build();
619+
assert_eq!(
620+
sut.to_date_end_of_period(),
621+
Date::from_str("2025-11-15").unwrap()
622+
);
623+
}
624+
625+
#[test]
626+
fn to_date_end_of_period_november_second_half() {
627+
let sut = Sut::builder()
628+
.year(2025.into())
629+
.month(Month::November)
630+
.half(MonthHalf::Second)
631+
.build();
632+
assert_eq!(
633+
sut.to_date_end_of_period(),
634+
Date::from_str("2025-11-30").unwrap()
635+
);
636+
}
637+
638+
#[test]
639+
fn to_date_end_of_period_december_first_half() {
640+
let sut = Sut::builder()
641+
.year(2025.into())
642+
.month(Month::December)
643+
.half(MonthHalf::First)
644+
.build();
645+
assert_eq!(
646+
sut.to_date_end_of_period(),
647+
Date::from_str("2025-12-15").unwrap()
648+
);
649+
}
650+
651+
#[test]
652+
fn to_date_end_of_period_december_second_half() {
653+
let sut = Sut::builder()
654+
.year(2025.into())
655+
.month(Month::December)
656+
.half(MonthHalf::Second)
657+
.build();
658+
assert_eq!(
659+
sut.to_date_end_of_period(),
660+
Date::from_str("2025-12-31").unwrap()
661+
);
662+
}
325663
}

0 commit comments

Comments
 (0)