Revision: 1777
Author: [email protected]
Date: Thu Dec 10 07:04:10 2009
Log: Add a basic multiple choice question.
http://code.google.com/p/simal/source/detail?r=1777

Added:
   
/trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/MultipleChoiceQuestion.java
   
/trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/TestMultipleChoiceQuestion.java

=======================================
--- /dev/null
+++  
/trunk/uk.ac.osswatch.simal.ssmm/src/main/uk/ac/osswatch/simal/ssmm/model/MultipleChoiceQuestion.java
    
Thu Dec 10 07:04:10 2009
@@ -0,0 +1,57 @@
+package uk.ac.osswatch.simal.ssmm.model;
+
+import java.util.HashMap;
+
+
+public class MultipleChoiceQuestion extends Question {
+       HashMap<String, String> options = new HashMap<String, String>();
+
+       /**
+        * Create a multiple choice question.
+        *
+        * @param label huamn readable label for the question
+        * @param text the text of the question
+        * @param details descriptive details about the question
+        * @param options the options available, where the key is used as a 
short  
hand for the question and the value is a description of the question.
+        */
+       public MultipleChoiceQuestion(String label, String text, String 
details,  
HashMap<String, String> options) {
+               super(label, text, details);
+               this.options = options;
+       }
+
+       /**
+        * Get a map of options available in response to this question.
+        *
+        * @return a hasmap keyed by the short version of the response. The 
value  
is a full description of the response.
+        */
+       public HashMap<String, String> getOptions() {
+               return options;
+       }
+
+       /**
+        * Set a map of options available to answer this question.
+        *
+        * @param options a hasmap keyed by the short version of the response.  
The value is a full description of the response.
+        */
+       public void setOptions(HashMap<String, String> options) {
+               this.options = options;
+       }
+
+       /**
+        * Add an option to the possible answers.
+        * @param option short version of the option
+        * @param description a full description of the option
+        */
+       public void addOption(String option, String description) {
+               options.put(option, description);
+       }
+
+       /**
+        * Remove an option to the possible answers.
+        * @param option short version of the option
+        */
+       public void removeOption(String option) {
+               options.remove(option);
+       }
+
+}
=======================================
--- /dev/null
+++  
/trunk/uk.ac.osswatch.simal.ssmm/src/test/uk/ac/osswatch/simal/ssmm/model/TestMultipleChoiceQuestion.java
        
Thu Dec 10 07:04:10 2009
@@ -0,0 +1,39 @@
+package uk.ac.osswatch.simal.ssmm.model;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.HashMap;
+
+public class TestMultipleChoiceQuestion {
+       static HashMap<String, String> options;
+       static MultipleChoiceQuestion question;
+
+       @BeforeClass
+       public static void createQuestion() {
+               options = new HashMap<String, String>();
+               options.put("One", "Option one");
+               options.put("Two", "Option two");
+               options.put("Three", "Option three");
+               options.put("Four", "Option four");
+
+               question = new 
MultipleChoiceQuestion(TestQuestion.QUESTION_LABEL,  
TestQuestion.QUESTION_TEXT, TestQuestion.QUESTION_DETAILS, options);
+       }
+
+       @Test
+       public void testOptionsSize() {
+               assertEquals("There is an incorrect number of options", 
options.size(),  
question.getOptions().size());
+       }
+
+       @Test
+       public void testAddRemoveOption() {
+               int originalSize = question.getOptions().size();
+               question.addOption("Five", "Option five");
+               assertEquals("There is an incorrect number of options after 
adding an  
option", originalSize + 1, question.getOptions().size());
+
+               question.removeOption("Five");
+               assertEquals("There is an incorrect number of options after 
removing an  
option", originalSize, question.getOptions().size());
+       }
+}

--

You received this message because you are subscribed to the Google Groups 
"Simal Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/simal-commits?hl=en.


Reply via email to