-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic Desireset wrapper (#29)
* feat: add DesireSet * docs: add code documentation * feat: add UpdateStatus to DesireSet * test: add DesireSet tests * fix: add in keyword and fix xml comment * chore: remove redundant using directive * refactor: use expression body definition
- Loading branch information
1 parent
33ea7e2
commit c0b9203
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Aplib.Core.Belief; | ||
using Aplib.Core.Desire.Goals; | ||
|
||
namespace Aplib.Core.Desire | ||
{ | ||
/// <inheritdoc /> | ||
public class DesireSet<TBeliefSet> : IDesireSet<TBeliefSet> | ||
where TBeliefSet : IBeliefSet | ||
{ | ||
/// <summary> | ||
/// Stores the main goal structure of the agent. | ||
/// </summary> | ||
private IGoalStructure<TBeliefSet> _mainGoal { get; } | ||
|
||
/// <inheritdoc /> | ||
public CompletionStatus Status => _mainGoal.Status; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DesireSet{TBeliefSet}" /> class. | ||
/// </summary> | ||
/// <param name="mainGoal">The main goal structure that the agent needs to complete.</param> | ||
public DesireSet(IGoalStructure<TBeliefSet> mainGoal) | ||
=> _mainGoal = mainGoal; | ||
|
||
/// <inheritdoc /> | ||
public IGoal GetCurrentGoal(TBeliefSet beliefSet) | ||
=> _mainGoal.GetCurrentGoal(beliefSet); | ||
|
||
/// <inheritdoc /> | ||
public void UpdateStatus(TBeliefSet beliefSet) | ||
=> _mainGoal.UpdateStatus(beliefSet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Aplib.Core.Belief; | ||
using Aplib.Core.Desire.Goals; | ||
|
||
namespace Aplib.Core.Desire | ||
{ | ||
/// <summary> | ||
/// Represents a set of goals that the agent has. | ||
/// This is the main structure that the agent will use to determine what it should do next. | ||
/// </summary> | ||
/// <typeparam name="TBeliefSet"></typeparam> | ||
public interface IDesireSet<in TBeliefSet> : ICompletable | ||
where TBeliefSet : IBeliefSet | ||
{ | ||
/// <summary> | ||
/// Gets the current goal using the given <see cref="IBeliefSet" />. | ||
/// </summary> | ||
/// <param name="beliefSet">The belief set of the agent.</param> | ||
/// <returns>The current goal to be fulfilled.</returns> | ||
IGoal GetCurrentGoal(TBeliefSet beliefSet); | ||
|
||
/// <summary> | ||
/// Updates the status of this <see cref="IDesireSet{TBeliefSet}"/>. | ||
/// </summary> | ||
/// <param name="beliefSet">The belief set of the agent.</param> | ||
void UpdateStatus(TBeliefSet beliefSet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Aplib.Core; | ||
using Aplib.Core.Belief; | ||
using Aplib.Core.Desire; | ||
using Aplib.Core.Desire.Goals; | ||
using FluentAssertions; | ||
using Moq; | ||
|
||
namespace Aplib.Tests.Core.Desire; | ||
|
||
public class DesireSetTests | ||
{ | ||
/// <summary> | ||
/// Given a desire set, | ||
/// When the GetCurrentGoal method is called, | ||
/// Then the desire set should return the current goal of the current goal structure. | ||
/// </summary> | ||
[Fact] | ||
public void DesireSet_WhenGetCurrentGoalIsCalled_ReturnsCurrentGoal() | ||
{ | ||
// Arrange | ||
IBeliefSet beliefSet = Mock.Of<IBeliefSet>(); | ||
IGoal goal = Mock.Of<IGoal>(); | ||
Mock<IGoalStructure<IBeliefSet>> goalStructure = new(); | ||
goalStructure | ||
.Setup(g => g.GetCurrentGoal(It.IsAny<IBeliefSet>())) | ||
.Returns(goal); | ||
Mock<DesireSet<IBeliefSet>> desireSet = new(goalStructure.Object); | ||
|
||
// Act | ||
IGoal currentGoal = desireSet.Object.GetCurrentGoal(beliefSet); | ||
|
||
// Assert | ||
currentGoal.Should().Be(goal); | ||
} | ||
|
||
/// <summary> | ||
/// Given a desire set, | ||
/// When the status is updated, | ||
/// Then the status of the goal structures are updated. | ||
/// </summary> | ||
[Fact] | ||
public void DesireSet_WhenStatusUpdated_ShouldUpdateGoalStructuresStatus() | ||
{ | ||
// Arrange | ||
Mock<IGoalStructure<IBeliefSet>> goalStructure = new(); | ||
Mock<DesireSet<IBeliefSet>> desireSet = new(goalStructure.Object); | ||
|
||
// Act | ||
desireSet.Object.UpdateStatus(It.IsAny<IBeliefSet>()); | ||
|
||
// Assert | ||
goalStructure.Verify(g => g.UpdateStatus(It.IsAny<IBeliefSet>()), Times.Once()); | ||
} | ||
|
||
/// <summary> | ||
/// Given a desire set, | ||
/// When the status is checked, | ||
/// Then the status should be the same as the main goal structure status. | ||
/// </summary> | ||
[Fact] | ||
public void DesireSet_WhenStatusIsChecked_ShouldBeSameAsMainGoal() | ||
{ | ||
// Arrange | ||
Mock<IGoalStructure<IBeliefSet>> goalStructure = new(); | ||
goalStructure.Setup(g => g.Status).Returns(CompletionStatus.Success); | ||
Mock<DesireSet<IBeliefSet>> desireSet = new(goalStructure.Object); | ||
|
||
// Act | ||
CompletionStatus status = desireSet.Object.Status; | ||
CompletionStatus expectedStatus = goalStructure.Object.Status; | ||
|
||
// Assert | ||
status.Should().Be(expectedStatus); | ||
} | ||
} |