Skip to content

Commit

Permalink
Merge pull request #256 from bschwehn/fix/superset-last-exercise-unit…
Browse files Browse the repository at this point in the history
…-test
  • Loading branch information
LiamMorrow authored Aug 27, 2024
2 parents 5a96fe9 + 7d5e923 commit 0a836b6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ session with
.RecordedExercises.SetItem(
0,
Sessions.CreateRecordedExercise(
exerciseIndex: 0,
null,
exercise =>
exercise with
Expand All @@ -33,6 +34,7 @@ exercise with
.SetItem(
1,
Sessions.CreateRecordedExercise(
exerciseIndex: 1,
null,
exercise =>
exercise with
Expand Down
48 changes: 30 additions & 18 deletions tests/LiftLog.Tests.App/SessionBehaviors/SessionSuperset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ x with
Exercise(5, supersetWithNext: false),
],
},
fillFirstSet: false
fillSets: []
)
);
Expand Down Expand Up @@ -180,21 +180,6 @@ x with
});
});
Describe("and the last completed set was exercise 6 (last exercise and superset with 5)")
.As(() =>
{
BeforeEach(() =>
{
session = CycleExerciseReps(6, 0);
});
It("Should end the session")
.When(() =>
{
var nextExercise = session.NextExercise;
nextExercise.Should().BeNull();
});
});
}
);

Expand All @@ -213,7 +198,7 @@ x with
Exercise(2, supersetWithNext: false),
],
},
fillFirstSet: false
fillSets: []
);
});
Expand Down Expand Up @@ -279,7 +264,7 @@ x with
Exercise(2, supersetWithNext: true),
],
},
fillFirstSet: false
fillSets: []
);
});
Expand Down Expand Up @@ -350,5 +335,32 @@ x with
});
});
});

Describe("When the last exercise is a completed superset")
.As(() =>
{
BeforeEach(() =>
{
session = Sessions.CreateSession(
sessionBlueprint: Blueprints.CreateSessionBlueprint() with
{
Exercises =
[
Exercise(0, supersetWithNext: false),
Exercise(1, supersetWithNext: true),
Exercise(2, supersetWithNext: false),
],
},
fillSets: [0, 1, 2]
);
});
It("Should end the session")
.When(() =>
{
var nextExercise = session.NextExercise;
nextExercise.Should().BeNull();
});
});
}
}
19 changes: 9 additions & 10 deletions tests/LiftLog.Tests.App/Sessions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class Sessions
public static Session CreateSession(
SessionBlueprint? sessionBlueprint = null,
Func<Session, Session>? transform = null,
bool fillFirstSet = true
int[]? fillSets = null
)
{
sessionBlueprint ??= Blueprints.CreateSessionBlueprint();
Expand All @@ -16,7 +16,7 @@ public static Session CreateSession(
Id: Guid.NewGuid(),
Blueprint: sessionBlueprint,
RecordedExercises: sessionBlueprint
.Exercises.Select(x => CreateRecordedExercise(x, fillFirstSet: fillFirstSet))
.Exercises.Select((x, i) => CreateRecordedExercise(i, x, fillSets: fillSets))
.ToImmutableList(),
Date: DateOnly.Parse("2021-04-05"),
Bodyweight: null
Expand All @@ -25,9 +25,10 @@ public static Session CreateSession(
}

public static RecordedExercise CreateRecordedExercise(
int exerciseIndex,
ExerciseBlueprint? exerciseBlueprint = null,
Func<RecordedExercise, RecordedExercise>? transform = null,
bool fillFirstSet = true
int[]? fillSets = null
)
{
exerciseBlueprint ??= Blueprints.CreateExerciseBlueprint();
Expand All @@ -39,17 +40,15 @@ public static RecordedExercise CreateRecordedExercise(
.Range(0, exerciseBlueprint.Sets)
.Select(
(i) =>
(fillFirstSet, i) switch
{
(true, 0) => new PotentialSet(
fillSets != null && fillSets.Contains(i)
? new PotentialSet(
new(
RepsCompleted: exerciseBlueprint.RepsPerSet,
CompletionTime: TimeOnly.Parse("14:32:00")
CompletionTime: TimeOnly.Parse("14:32:00").AddMinutes(exerciseIndex * 5 + i)
),
0
),
_ => new PotentialSet(null, 0),
}
)
: new PotentialSet(null, 0)
)
.ToImmutableList(),
Notes: null,
Expand Down

0 comments on commit 0a836b6

Please sign in to comment.