Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Microting.TimePlanningBase.Infrastructure.Data.Entities;
using Microting.TimePlanningBase.Infrastructure.Helpers;
using NUnit.Framework;
using TimePlanning.Pn.Infrastructure.Helpers;
using TimePlanning.Pn.Infrastructure.Models.Planning;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void OffMode_Shift1_SumsAllSlots_FloorTo5Min_Returns30Min()
{
var reg = BuildRow16288Shape();

var result = PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals: false);
var result = FlexChain.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals: false);

Assert.That(result, Is.EqualTo(30 * 60),
"Shift 1 OFF: 0 + 5 + 20 + 5 = 30 min across Pause1/Pause10/Pause11/Pause12");
Expand All @@ -81,7 +82,7 @@ public void OffMode_Shift2_SinglePrimarySlot_Returns5Min()
{
var reg = BuildRow16288Shape();

var result = PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 2, useOneMinuteIntervals: false);
var result = FlexChain.ComputeShiftPauseSeconds(reg, 2, useOneMinuteIntervals: false);

Assert.That(result, Is.EqualTo(5 * 60),
"Shift 2 OFF: Pause2 19:13:26 -> 19:16:52 crosses 19:15 = 5 min");
Expand All @@ -92,7 +93,7 @@ public void OnMode_Shift1_SumsExactSecondDeltasAcrossAllSlots_Returns1985s()
{
var reg = BuildRow16288Shape();

var result = PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals: true);
var result = FlexChain.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals: true);

// 162 (2m42s) + 523 (8m43s) + 1252 (20m52s) + 48 (0m48s) = 1985 s.
Assert.That(result, Is.EqualTo(1985),
Expand All @@ -104,7 +105,7 @@ public void OnMode_Shift2_ExactSecondDelta_Returns206s()
{
var reg = BuildRow16288Shape();

var result = PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 2, useOneMinuteIntervals: true);
var result = FlexChain.ComputeShiftPauseSeconds(reg, 2, useOneMinuteIntervals: true);

// 19:16:52 - 19:13:26 = 3m26s = 206 s.
Assert.That(result, Is.EqualTo(206),
Expand All @@ -122,8 +123,8 @@ public void OffMode_DayTotalAcrossShifts_Returns35Min()
{
var reg = BuildRow16288Shape();

var shift1 = PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals: false);
var shift2 = PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 2, useOneMinuteIntervals: false);
var shift1 = FlexChain.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals: false);
var shift2 = FlexChain.ComputeShiftPauseSeconds(reg, 2, useOneMinuteIntervals: false);

Assert.That(shift1 + shift2, Is.EqualTo(35 * 60),
"Day total OFF = 30 + 5 = 35 min");
Expand All @@ -144,7 +145,7 @@ public void NoTimestampedSlot_FallsBackToLegacyPrimaryPauseId(bool useOneMinuteI
Pause3Id = 4, // legacy 15-min pause: (4 - 1) * 5 = 15 min
};

var result = PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 3, useOneMinuteIntervals);
var result = FlexChain.ComputeShiftPauseSeconds(reg, 3, useOneMinuteIntervals);

Assert.That(result, Is.EqualTo(15 * 60),
"No timestamped slot => legacy primary Pause3Id fallback = 15 min");
Expand All @@ -170,7 +171,7 @@ public void OrphanedStartOnlySlot_FallsBackToLegacyPrimaryPauseId(bool useOneMin
Pause1Id = 4, // legacy 15-min pause: (4 - 1) * 5 = 15 min
};

var result = PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals);
var result = FlexChain.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals);

Assert.That(result, Is.EqualTo(15 * 60),
"Orphaned start-only slot is not a complete slot => legacy Pause1Id fallback = 15 min");
Expand All @@ -190,7 +191,7 @@ public void PartialTimestamp_StartedAtOnly_FallsBackToLegacyPauseId()
Pause1StartedAt = new DateTime(2026, 6, 19, 10, 0, 0, DateTimeKind.Utc),
Pause1StoppedAt = null,
};
Assert.That(PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals: false), Is.EqualTo(900),
Assert.That(FlexChain.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals: false), Is.EqualTo(900),
"Half-record (StartedAt only) must not suppress the legacy PauseId fallback");
}

Expand All @@ -210,7 +211,7 @@ public void Override_WinsOverSlotSum(bool useOneMinuteIntervals)
var reg = BuildRow16288Shape();
reg.Pause1OverrideMinutes = 12;

var result = PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals);
var result = FlexChain.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals);

Assert.That(result, Is.EqualTo(12 * 60),
"Override must replace the slot sum entirely.");
Expand All @@ -227,7 +228,7 @@ public void Override_Zero_MeansZeroPause(bool useOneMinuteIntervals)
var reg = BuildRow16288Shape();
reg.Pause1OverrideMinutes = 0;

var result = PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals);
var result = FlexChain.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals);

Assert.That(result, Is.EqualTo(0),
"Override = 0 means zero pause, not the slot sum.");
Expand All @@ -243,7 +244,7 @@ public void Override_Null_FallsBackToSlotSum()
var reg = BuildRow16288Shape();
reg.Pause1OverrideMinutes = null;

var result = PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals: false);
var result = FlexChain.ComputeShiftPauseSeconds(reg, 1, useOneMinuteIntervals: false);

Assert.That(result, Is.EqualTo(30 * 60),
"Null override must fall back to the all-slots sum (30 min).");
Expand All @@ -259,7 +260,7 @@ public void Override_IsPerShift_DoesNotLeakAcrossShifts()
var reg = BuildRow16288Shape();
reg.Pause1OverrideMinutes = 99;

var shift2 = PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 2, useOneMinuteIntervals: false);
var shift2 = FlexChain.ComputeShiftPauseSeconds(reg, 2, useOneMinuteIntervals: false);

Assert.That(shift2, Is.EqualTo(5 * 60),
"Shift 2 has no override and must still sum its own slot (5 min).");
Expand Down Expand Up @@ -306,7 +307,7 @@ public void Inference_EditOnlyStartStop_NonFiveMinSlotSum_LeavesOverrideNull()
Pause10StoppedAt = Date.AddHours(11).AddMinutes(20),
};
// Sanity: the slot sum is 33 min, not a 5-min multiple.
Assert.That(PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 1, true),
Assert.That(FlexChain.ComputeShiftPauseSeconds(reg, 1, true),
Is.EqualTo(33 * 60), "Pre-condition: slot sum is 33 min.");

var preEditShownTicks = TimePlanningPlanningService.CaptureCurrentShiftShownTicks(reg);
Expand All @@ -316,7 +317,7 @@ public void Inference_EditOnlyStartStop_NonFiveMinSlotSum_LeavesOverrideNull()

Assert.That(reg.Pause1OverrideMinutes, Is.Null,
"Unchanged pause (Break == pre-edit Pause1Id) must NOT lock an override.");
Assert.That(PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 1, true),
Assert.That(FlexChain.ComputeShiftPauseSeconds(reg, 1, true),
Is.EqualTo(33 * 60), "Netto pause still reflects the recorded slot sum.");
}

Expand Down Expand Up @@ -419,7 +420,7 @@ public void ExplicitClear_RevertsOverrideToNull_FallsBackToSlotSum()

Assert.That(reg.Pause1OverrideMinutes, Is.Null,
"Explicit clear must revert the override to null.");
Assert.That(PlanRegistrationHelper.ComputeShiftPauseSeconds(reg, 1, false),
Assert.That(FlexChain.ComputeShiftPauseSeconds(reg, 1, false),
Is.EqualTo(5 * 60), "After clear, pause falls back to the recorded slot sum (5 min).");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microting.TimePlanningBase.Infrastructure.Data;
using AssignedSiteEntity = Microting.TimePlanningBase.Infrastructure.Data.Entities.AssignedSite;
using Microting.TimePlanningBase.Infrastructure.Data.Entities;
using Microting.TimePlanningBase.Infrastructure.Helpers;
using NUnit.Framework;
using TimePlanning.Pn.Infrastructure.Helpers;

Expand Down Expand Up @@ -46,7 +47,7 @@ public void ComputeNetto_PrefersPauseTimestamps_OverCorruptPauseId()
Pause1Id = 145, // CORRUPT absolute tick (12:00)
};

var netto = PlanRegistrationHelper.ComputeNettoSecondsFromDateTimeShifts(pr);
var netto = FlexChain.ComputeNettoSecondsFromDateTimeShifts(pr);

// 8h - 30m = 7h30m = 27000s, derived from timestamps not the id.
Assert.That(netto, Is.EqualTo(27000));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microting.TimePlanningBase.Infrastructure.Data.Entities;
using Microting.TimePlanningBase.Infrastructure.Helpers;
using NUnit.Framework;
using TimePlanning.Pn.Infrastructure.Helpers;

Expand Down Expand Up @@ -219,12 +220,12 @@ public void SeedFallback_NullPredecessor_IsZero()
{
Assert.Multiple(() =>
{
Assert.That(PlanRegistrationHelper.SumFlexEndSecondsWithFallback(null), Is.EqualTo(0));
Assert.That(FlexChain.SumFlexEndSecondsWithFallback(null), Is.EqualTo(0));
Assert.That(
PlanRegistrationHelper.SumFlexEndSecondsWithFallback(null, preIsOneMinute: false),
FlexChain.SumFlexEndSecondsWithFallback(null, preIsOneMinute: false),
Is.EqualTo(0), "…whatever the mode argument says.");
Assert.That(
PlanRegistrationHelper.SumFlexEndSecondsWithFallback(null, preIsOneMinute: true),
FlexChain.SumFlexEndSecondsWithFallback(null, preIsOneMinute: true),
Is.EqualTo(0));
});
}
Expand All @@ -233,7 +234,7 @@ public void SeedFallback_NullPredecessor_IsZero()
public void SeedFallback_PopulatedSecondsWin()
{
var pre = new PlanRegistration { SumFlexEndInSeconds = 7261, SumFlexEnd = 99 };
Assert.That(PlanRegistrationHelper.SumFlexEndSecondsWithFallback(pre), Is.EqualTo(7261),
Assert.That(FlexChain.SumFlexEndSecondsWithFallback(pre), Is.EqualTo(7261),
"When the seconds column is populated it is the source of truth.");
}

Expand All @@ -248,15 +249,15 @@ public void SeedFallback_ZeroSeconds_FallsBackToTheDecimalBalance()
Assert.Multiple(() =>
{
Assert.That(
PlanRegistrationHelper.SumFlexEndSecondsWithFallback(
FlexChain.SumFlexEndSecondsWithFallback(
new PlanRegistration { SumFlexEndInSeconds = 0, SumFlexEnd = 12.5 }),
Is.EqualTo(45000));
Assert.That(
PlanRegistrationHelper.SumFlexEndSecondsWithFallback(
FlexChain.SumFlexEndSecondsWithFallback(
new PlanRegistration { SumFlexEndInSeconds = 0, SumFlexEnd = -2.25 }),
Is.EqualTo(-8100), "A negative carried balance survives the fallback.");
Assert.That(
PlanRegistrationHelper.SumFlexEndSecondsWithFallback(
FlexChain.SumFlexEndSecondsWithFallback(
new PlanRegistration { SumFlexEndInSeconds = 0, SumFlexEnd = 0 }),
Is.EqualTo(0), "A genuine zero and an unbackfilled zero agree.");
});
Expand Down Expand Up @@ -297,16 +298,16 @@ public void SeedFallback_FiveMinutePredecessor_IgnoresStaleSecondsColumn()
Assert.Multiple(() =>
{
Assert.That(
PlanRegistrationHelper.SumFlexEndSecondsWithFallback(pre, preIsOneMinute: false),
FlexChain.SumFlexEndSecondsWithFallback(pre, preIsOneMinute: false),
Is.EqualTo(TrueDecimalSeconds),
"A five-minute row carries its balance in the decimal ONLY; a "
+ "non-zero seconds column there is residue, never a balance.");
Assert.That(
PlanRegistrationHelper.SumFlexEndSecondsWithFallback(pre, preIsOneMinute: true),
FlexChain.SumFlexEndSecondsWithFallback(pre, preIsOneMinute: true),
Is.EqualTo(StaleSeconds),
"A one-minute predecessor keeps the seconds column as its truth.");
Assert.That(
PlanRegistrationHelper.SumFlexEndSecondsWithFallback(pre),
FlexChain.SumFlexEndSecondsWithFallback(pre),
Is.EqualTo(StaleSeconds),
"Unknown mode keeps the pre-existing behaviour.");
});
Expand All @@ -319,7 +320,7 @@ public void SeedFallback_FiveMinutePredecessor_WithZeroSeconds_IsUnchanged()
// rules agree and the decimal answers either way.
var pre = new PlanRegistration { SumFlexEnd = 12.5, SumFlexEndInSeconds = 0 };
Assert.That(
PlanRegistrationHelper.SumFlexEndSecondsWithFallback(pre, preIsOneMinute: false),
FlexChain.SumFlexEndSecondsWithFallback(pre, preIsOneMinute: false),
Is.EqualTo(45000));
}

Expand Down Expand Up @@ -365,7 +366,7 @@ public void MarkerFiveMinutePredecessorAfterTheEffectiveDate_SeedsFromTheDecimal
PlanHoursInSeconds = 28800
};

PlanRegistrationHelper.ApplyNettoFlexChainSecondPrecision(
FlexChain.ApplyNettoFlexChainSecondPrecision(
successor, pre, timeline.WasOneMinuteFor(pre));

Assert.Multiple(() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using TimePlanning.Pn.Infrastructure.Helpers;
using Microting.TimePlanningBase.Infrastructure.Helpers;

namespace TimePlanning.Pn.Test;

Expand Down
Loading
Loading