Reputation: 2538
Well i was reading Check if the string contains all inputs on the list And tried it, but when i had something like a basic question such as 'Who discovered Austrlia' and if i put the key words in the answer as 'captain,cook' it would say i got the question wrong.
Any idea what im doing wrong; code im using:
GivenAnswer = textBox1.Text;
String invariantText = textBox1.Text.ToUpperInvariant();
bool matches = KeyWords.All(kw => invariantText.Contains(kw.ToUpperInvariant()));
if (matches)
{
correct++;
if (InstantResult) { MessageBox.Show("Questions Answered Correctly", "Answer Results", MessageBoxButtons.OK, MessageBoxIcon.Information); }
}
else
{
incorrect++;
if (InstantResult) { MessageBox.Show("Question Answered Wrong, sorry!", "Answer Result", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); }
}
Study_Helper.Form1.QuestionResults.Add(Question + "|" + (matches ? "true" : "false") + "|" + (Exact? "N/A" : KeyWords_Found()) + "|" + (Hint_Used ? "true" : "false") + "|" + GivenAnswer.ToLowerInvariant());
LoadUp();
textBox1.Clear();
textBox1.Focus();
Upvotes: 2
Views: 428
Reputation: 3200
For debugging purposes, confirm that KeyWords
and invariantText
contain expected values. Use the debugger or Console.WriteLine().
This is where unit testing becomes valuable. NUnit or MSTest are available for C#/VS development.
Upvotes: 1
Reputation: 2538
Thanks to the first comment on my question. I relised i never actually cleared the arraylist, make sure you clear the arraylist after you do this check as to not get more values in your keyword list then wanted.
KeyWords.Clear();
Upvotes: 0