Skip to content

Commit

Permalink
Add tests that ensure supersets behave in an intended manner
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamMorrow committed Aug 20, 2024
1 parent 3999099 commit 4e4bdab
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 18 deletions.
1 change: 1 addition & 0 deletions LiftLog.Maui/LiftLog.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<RunAOTCompilation>true</RunAOTCompilation>
<AndroidStripILAfterAOT>true</AndroidStripILAfterAOT>
<AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
<EnableLLVM>true</EnableLLVM>
</PropertyGroup>
Expand Down
14 changes: 13 additions & 1 deletion LiftLog.Ui/Store/CurrentSession/CurrentSessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,17 @@ public record CurrentSessionState(
Session? HistorySession,
Session? FeedSession,
Guid? LatestSetTimerNotificationId
);
)
{
public static CurrentSessionState FromWorkoutSession(Session session)
{
return new CurrentSessionState(
IsHydrated: true,
WorkoutSession: session,
HistorySession: null,
FeedSession: null,
LatestSetTimerNotificationId: null
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public static void Spec()
);
// Assert
Assert.Equal(data1, decryptedData1);
Assert.Equal(data2, decryptedData2);
Assert.Equal(encryptedData1.IV, encryptedData2.IV);
data1.Should().Equal(decryptedData1);
data2.Should().Equal(decryptedData2);
encryptedData1.IV.Should().BeEquivalentTo(encryptedData2.IV);
});
});
Expand All @@ -113,7 +113,7 @@ public static void Spec()
encryptedData.EncryptedPayload[0] ^= 0xFF;
// Assert
await Assert.ThrowsAsync<SignatureMismatchException>(
Assert.ThrowsAsync<SignatureMismatchException>(
async () =>
await sut.DecryptAesCbcAndVerifyRsa256PssAsync(
encryptedData,
Expand Down
4 changes: 2 additions & 2 deletions tests/LiftLog.Tests.App/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
global using System.Collections.Immutable;
global using FluentAssertions;
global using NSubstitute;
global using NUnit.Framework;
global using Oatmilk;
global using Oatmilk.Nunit;
global using static Oatmilk.TestBuilder;
global using Oatmilk.Xunit;
global using Xunit;
10 changes: 4 additions & 6 deletions tests/LiftLog.Tests.App/LiftLog.Tests.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Oatmilk.Xunit" Version="0.0.8" />
<PackageReference Include="Oatmilk.Nunit" Version="0.1.3" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
191 changes: 191 additions & 0 deletions tests/LiftLog.Tests.App/SessionBehaviors/SessionSuperset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
using LiftLog.Lib.Models;
using LiftLog.Ui.Store.CurrentSession;

namespace LiftLog.Tests.App.SessionBehaviors;

public class SessionSupersetTests
{
[Describe("Session supersets")]
public void Spec()
{
Describe(
"When given a session with supersets",
() =>
{
Session session = null!;
CurrentSessionState GetState() => CurrentSessionState.FromWorkoutSession(session);
Session CycleExerciseReps(int exerciseIndex, int setIndex) =>
CurrentSessionReducers
.CycleExerciseReps(
GetState(),
new CycleExerciseRepsAction(
SessionTarget.WorkoutSession,
ExerciseIndex: exerciseIndex,
SetIndex: setIndex
)
)
.WorkoutSession!;
ExerciseBlueprint Exercise(int index, bool supersetWithNext) =>
Blueprints.CreateExerciseBlueprint(x =>
x with
{
Name = $"Ex{index}",
SupersetWithNext = supersetWithNext
}
);
BeforeEach(
() =>
session = Sessions.CreateSession(
sessionBlueprint: Blueprints.CreateSessionBlueprint() with
{
Exercises =
[
Exercise(0, supersetWithNext: false),
Exercise(1, supersetWithNext: true),
Exercise(2, supersetWithNext: false),
Exercise(3, supersetWithNext: true),
Exercise(4, supersetWithNext: true),
Exercise(5, supersetWithNext: false)
]
},
fillFirstSet: false
)
);
It("should have the first exercise and set as the next exercise")
.When(() =>
{
var nextExercise = session.NextExercise;
nextExercise.Should().NotBeNull();
nextExercise.Blueprint.Name.Should().Be(session.RecordedExercises[0].Blueprint.Name);

Check warning on line 62 in tests/LiftLog.Tests.App/SessionBehaviors/SessionSuperset.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.

Check warning on line 62 in tests/LiftLog.Tests.App/SessionBehaviors/SessionSuperset.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
});
Describe("and the last completed set was the first exercise (not a superset)")
.As(() =>
{
BeforeEach(() =>
{
session = CycleExerciseReps(0, 0);
});
It(
"Should have the next set be the first exercise",
() =>
{
var nextExercise = session.NextExercise;
nextExercise.Should().NotBeNull();
nextExercise

Check warning on line 79 in tests/LiftLog.Tests.App/SessionBehaviors/SessionSuperset.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.

Check warning on line 79 in tests/LiftLog.Tests.App/SessionBehaviors/SessionSuperset.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
.Blueprint.Name.Should()
.Be(session.RecordedExercises[0].Blueprint.Name);
}
);
});
Describe(
"and the last completed set was the second exercise (a superset with the third exercise)"
)
.As(() =>
{
BeforeEach(() =>
{
session = CycleExerciseReps(1, 0);
});
It("Should have the next set be the third exercise")
.When(() =>
{
var nextExercise = session.NextExercise;
nextExercise.Should().NotBeNull();
nextExercise

Check warning on line 101 in tests/LiftLog.Tests.App/SessionBehaviors/SessionSuperset.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.

Check warning on line 101 in tests/LiftLog.Tests.App/SessionBehaviors/SessionSuperset.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
.Blueprint.Name.Should()
.Be(session.RecordedExercises[2].Blueprint.Name);
});
});
Describe(
"and the last completed set was the third exercise (a superset with the previous exercise)"
)
.As(() =>
{
BeforeEach(() =>
{
session = CycleExerciseReps(2, 0);
});
It("Should have the next set be the second exercise")
.When(() =>
{
var nextExercise = session.NextExercise;
nextExercise.Should().NotBeNull();
nextExercise

Check warning on line 121 in tests/LiftLog.Tests.App/SessionBehaviors/SessionSuperset.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
.Blueprint.Name.Should()
.Be(session.RecordedExercises[1].Blueprint.Name);
});
});
Describe(
"and the last completed set was the fourth exercise (a superset with the fifth and sixth exercise)"
)
.As(() =>
{
BeforeEach(() =>
{
session = CycleExerciseReps(3, 0);
});
It("Should have the next set be the fifth exercise")
.When(() =>
{
var nextExercise = session.NextExercise;
nextExercise.Should().NotBeNull();
nextExercise

Check warning on line 141 in tests/LiftLog.Tests.App/SessionBehaviors/SessionSuperset.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
.Blueprint.Name.Should()
.Be(session.RecordedExercises[4].Blueprint.Name);
});
});
Describe(
"and the last completed set was the fifth exercise (a superset with the fourth and sixth exercise)"
)
.As(() =>
{
BeforeEach(() =>
{
session = CycleExerciseReps(4, 0);
});
It("Should have the next set be the sixth exercise")
.When(() =>
{
var nextExercise = session.NextExercise;
nextExercise.Should().NotBeNull();
nextExercise

Check warning on line 162 in tests/LiftLog.Tests.App/SessionBehaviors/SessionSuperset.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
.Blueprint.Name.Should()
.Be(session.RecordedExercises[5].Blueprint.Name);
});
});
Describe(
"and the last completed set was the sixth exercise (a superset with the fourth and fifth exercise)"
)
.As(() =>
{
BeforeEach(() =>
{
session = CycleExerciseReps(4, 0);
});
It("Should have the next set be the fourth exercise")
.When(() =>
{
var nextExercise = session.NextExercise;
nextExercise.Should().NotBeNull();
nextExercise

Check warning on line 183 in tests/LiftLog.Tests.App/SessionBehaviors/SessionSuperset.cs

View workflow job for this annotation

GitHub Actions / test

Dereference of a possibly null reference.
.Blueprint.Name.Should()
.Be(session.RecordedExercises[4].Blueprint.Name);
});
});
}
);
}
}
12 changes: 7 additions & 5 deletions tests/LiftLog.Tests.App/Sessions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public static class Sessions
{
public static Session CreateSession(
SessionBlueprint? sessionBlueprint = null,
Func<Session, Session>? transform = null
Func<Session, Session>? transform = null,
bool fillFirstSet = true
)
{
sessionBlueprint ??= Blueprints.CreateSessionBlueprint();
Expand All @@ -15,7 +16,7 @@ public static Session CreateSession(
Id: Guid.NewGuid(),
Blueprint: sessionBlueprint,
RecordedExercises: sessionBlueprint
.Exercises.Select(x => CreateRecordedExercise(x))
.Exercises.Select(x => CreateRecordedExercise(x, fillFirstSet: fillFirstSet))
.ToImmutableList(),
Date: DateOnly.Parse("2021-04-05"),
Bodyweight: null
Expand All @@ -25,7 +26,8 @@ public static Session CreateSession(

public static RecordedExercise CreateRecordedExercise(
ExerciseBlueprint? exerciseBlueprint = null,
Func<RecordedExercise, RecordedExercise>? transform = null
Func<RecordedExercise, RecordedExercise>? transform = null,
bool fillFirstSet = true
)
{
exerciseBlueprint ??= Blueprints.CreateExerciseBlueprint();
Expand All @@ -37,9 +39,9 @@ public static RecordedExercise CreateRecordedExercise(
.Range(0, exerciseBlueprint.Sets)
.Select(
(i) =>
i switch
(fillFirstSet, i) switch
{
0
(true, 0)
=> new PotentialSet(
new(
RepsCompleted: exerciseBlueprint.RepsPerSet,
Expand Down

0 comments on commit 4e4bdab

Please sign in to comment.