Skip to content

Commit 68d1d2a

Browse files
author
Jack Brookes
committed
fix & test early exit bug with adhoc headers
1 parent 3716bf0 commit 68d1d2a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Assets/UXF/Scripts/FileIOManager.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,15 @@ public void WriteTrials(List<ResultsDictionary> dictList, WriteFileInfo writeFil
231231
// add all observations to the row, in correct order.
232232
// check if null, if so assign to empty string (?? operator)
233233
var row = headers
234-
.Select(header => (dict[header] ?? string.Empty).ToString());
234+
.Select(header =>
235+
{
236+
object val;
237+
try { val = dict[header]; }
238+
catch (KeyNotFoundException) { val = string.Empty; }
239+
240+
return val.ToString();
241+
}
242+
);
235243

236244
// join to string & store in output
237245
csvRows[i + 1] = string.Join(",", row.ToArray());

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ public void RunTrialsAdHocResultsAdd()
122122
Assert.AreEqual("directory,experiment,ppid,session_num,trial_num,block_num,trial_num_in_block,start_time,end_time,observation,null_observation,not_customheader_observation", firstLine);
123123
}
124124

125+
[Test]
126+
public void RunTrialsAdHocResultsAddEarlyExit()
127+
{
128+
Start(true);
129+
session.blocks[0].trials[0].Begin();
130+
session.blocks[0].trials[0].result["not_customheader_observation"] = "something";
131+
session.blocks[0].trials[0].End();
132+
133+
session.blocks[0].trials[1].Begin();
134+
Finish(); // check we dont throw an error
135+
}
136+
125137
}
126138

127139
}

0 commit comments

Comments
 (0)