File tree Expand file tree Collapse file tree 2 files changed +66
-5
lines changed Expand file tree Collapse file tree 2 files changed +66
-5
lines changed Original file line number Diff line number Diff line change @@ -618,9 +618,25 @@ Trial GetPrevTrial()
618
618
/// </summary>
619
619
/// <returns></returns>
620
620
Trial GetFirstTrial ( )
621
- {
622
- var firstBlock = blocks [ 0 ] ;
623
- return firstBlock . trials [ 0 ] ;
621
+ {
622
+ Block firstBlock ;
623
+ try
624
+ {
625
+ firstBlock = blocks [ 0 ] ;
626
+ }
627
+ catch ( ArgumentOutOfRangeException )
628
+ {
629
+ throw new NoSuchTrialException ( "There is no first trial because no blocks have been created!" ) ;
630
+ }
631
+
632
+ try
633
+ {
634
+ return firstBlock . trials [ 0 ] ;
635
+ }
636
+ catch ( ArgumentOutOfRangeException )
637
+ {
638
+ throw new NoSuchTrialException ( "There is no first trial. No trials exist in the first block." ) ;
639
+ }
624
640
}
625
641
626
642
/// <summary>
@@ -629,8 +645,24 @@ Trial GetFirstTrial()
629
645
/// <returns></returns>
630
646
Trial GetLastTrial ( )
631
647
{
632
- var lastBlock = blocks [ blocks . Count - 1 ] ;
633
- return lastBlock . trials [ lastBlock . trials . Count - 1 ] ;
648
+ Block lastBlock ;
649
+ try
650
+ {
651
+ lastBlock = blocks [ 0 ] ;
652
+ }
653
+ catch ( ArgumentOutOfRangeException )
654
+ {
655
+ throw new NoSuchTrialException ( "There is no last trial because no blocks have been created!" ) ;
656
+ }
657
+
658
+ try
659
+ {
660
+ return lastBlock . trials [ lastBlock . trials . Count - 1 ] ;
661
+ }
662
+ catch ( ArgumentOutOfRangeException )
663
+ {
664
+ throw new NoSuchTrialException ( "There is no last trial. No trials exist in the last block." ) ;
665
+ }
634
666
}
635
667
636
668
/// <summary>
Original file line number Diff line number Diff line change @@ -129,6 +129,35 @@ public void SwapTrials()
129
129
session . blocks = new List < Block > ( ) ;
130
130
131
131
}
132
+
133
+ [ Test ]
134
+ public void InvalidTrialAccess ( )
135
+ {
136
+ Block block = session . CreateBlock ( ) ;
137
+
138
+ Assert . Throws < NoSuchTrialException > (
139
+ delegate { Trial t = session . FirstTrial ; }
140
+ ) ;
141
+
142
+ Assert . Throws < NoSuchTrialException > (
143
+ delegate { Trial t = session . LastTrial ; }
144
+ ) ;
145
+
146
+ // reset blocks
147
+ session . blocks = new List < Block > ( ) ;
148
+ }
149
+
150
+ [ Test ]
151
+ public void InvalidBlockAccess ( )
152
+ {
153
+ Assert . Throws < NoSuchTrialException > (
154
+ delegate { Trial t = session . FirstTrial ; }
155
+ ) ;
156
+
157
+ Assert . Throws < NoSuchTrialException > (
158
+ delegate { Trial t = session . LastTrial ; }
159
+ ) ;
160
+ }
132
161
133
162
}
134
163
You can’t perform that action at this time.
0 commit comments