Skip to content
Open
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
4 changes: 3 additions & 1 deletion LuckySpin.Test/SpinServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ public void SpinService_CalculateAvgWins_WinningSpin()
//TODO: Use the Setup() and Returns() methods of mockRepo
// to arrange for a consistent, expected output based on TestData

mockRepo.Setup(r => r.GetSpins()).Returns(SpinListData.GetSpins());
mockRepo.Setup(r => r.GetCount()).Returns(SpinListData.GetCount());
var service = new SpinService(mockRepo.Object);

//Act - run the method that you are testing and get a result
double result = service.CalculateAvgWins();

//Assert - compare the expected output from TestData to the method result
// TODO: check the repo data for the number of previous spins and wins, add one winning spin
double wins = 1/*???*/, count=1/*???*/;
double wins = 4 + 1 /*???*/, count = SpinListData.GetCount() + 1;
double expected = wins / count;
Assert.Equal(expected, result);
}
Expand Down
16 changes: 15 additions & 1 deletion LuckySpin/Services/SpinService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ public SpinService(ISpinRepository sr)
public double CalculateAvgWins()
{
//TODO: Write logic to use the "real" spinRepository NOT the test data
return .1;
Spin spin = new Spin();
double count = spinRepository.GetCount() + 1;
double sum = 1;
double result = 0;
double wins = 0;
for (int i = 1; i < count; i++)
{
wins = 4;
if (spin.IsWinning == true)
{
wins++;
}
result = (wins + 1) / count;
}
return result;
}

public Spin SpinIt(int luck)
Expand Down