Skip to content

Commit c4ddf69

Browse files
committed
Fixed lasttrial access, wrote tests to catch these errors
1 parent 0f91f47 commit c4ddf69

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Assets/UXF/Scripts/Session.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public class Session : MonoBehaviour
158158
public Trial PrevTrial { get { return GetPrevTrial(); } }
159159

160160
/// <summary>
161-
/// Get the last trial in the last block of the session.
161+
/// Get the first trial in the first block of the session.
162162
/// </summary>
163163
public Trial FirstTrial { get { return GetFirstTrial(); } }
164164

@@ -648,7 +648,7 @@ Trial GetLastTrial()
648648
Block lastBlock;
649649
try
650650
{
651-
lastBlock = blocks[0];
651+
lastBlock = blocks[blocks.Count - 1];
652652
}
653653
catch (ArgumentOutOfRangeException)
654654
{

Assets/UXF/Scripts/Tests/Editor/TestSessionBuilding.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void SwapTrials()
133133
[Test]
134134
public void InvalidTrialAccess()
135135
{
136-
Block block = session.CreateBlock();
136+
session.CreateBlock();
137137

138138
Assert.Throws<NoSuchTrialException>(
139139
delegate { Trial t = session.FirstTrial; }
@@ -158,6 +158,19 @@ public void InvalidBlockAccess()
158158
delegate { Trial t = session.LastTrial; }
159159
);
160160
}
161+
162+
[Test]
163+
public void FirstLast()
164+
{
165+
Block block1 = session.CreateBlock(10);
166+
Block block2 = session.CreateBlock(10);
167+
168+
Assert.AreEqual(block1.trials[0], session.FirstTrial);
169+
Assert.AreEqual(block2.trials[9], session.LastTrial);
170+
171+
// reset blocks
172+
session.blocks = new List<Block>();
173+
}
161174

162175
}
163176

0 commit comments

Comments
 (0)