Skip to content

Dev pika trial check issue #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 25, 2019
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
42 changes: 37 additions & 5 deletions Assets/UXF/Scripts/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,25 @@ Trial GetPrevTrial()
/// </summary>
/// <returns></returns>
Trial GetFirstTrial()
{
var firstBlock = blocks[0];
return firstBlock.trials[0];
{
Block firstBlock;
try
{
firstBlock = blocks[0];
}
catch (ArgumentOutOfRangeException)
{
throw new NoSuchTrialException("There is no first trial because no blocks have been created!");
}

try
{
return firstBlock.trials[0];
}
catch (ArgumentOutOfRangeException)
{
throw new NoSuchTrialException("There is no first trial. No trials exist in the first block.");
}
}

/// <summary>
Expand All @@ -629,8 +645,24 @@ Trial GetFirstTrial()
/// <returns></returns>
Trial GetLastTrial()
{
var lastBlock = blocks[blocks.Count - 1];
return lastBlock.trials[lastBlock.trials.Count - 1];
Block lastBlock;
try
{
lastBlock = blocks[0];
}
catch (ArgumentOutOfRangeException)
{
throw new NoSuchTrialException("There is no last trial because no blocks have been created!");
}

try
{
return lastBlock.trials[lastBlock.trials.Count - 1];
}
catch (ArgumentOutOfRangeException)
{
throw new NoSuchTrialException("There is no last trial. No trials exist in the last block.");
}
}

/// <summary>
Expand Down
29 changes: 29 additions & 0 deletions Assets/UXF/Scripts/Tests/Editor/TestSessionBuilding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,35 @@ public void SwapTrials()
session.blocks = new List<Block>();

}

[Test]
public void InvalidTrialAccess()
{
Block block = session.CreateBlock();

Assert.Throws<NoSuchTrialException>(
delegate { Trial t = session.FirstTrial; }
);

Assert.Throws<NoSuchTrialException>(
delegate { Trial t = session.LastTrial; }
);

// reset blocks
session.blocks = new List<Block>();
}

[Test]
public void InvalidBlockAccess()
{
Assert.Throws<NoSuchTrialException>(
delegate { Trial t = session.FirstTrial; }
);

Assert.Throws<NoSuchTrialException>(
delegate { Trial t = session.LastTrial; }
);
}

}

Expand Down