Changeset 1210 for trunk


Ignore:
Timestamp:
05/23/13 16:27:53 (12 years ago)
Author:
pharms
Message:
  • complete refactoring of task tree model with a separation of task models and task instances
Location:
trunk/autoquest-core-usability-test/src/test/java/de/ugoe/cs/autoquest/usability
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-usability-test/src/test/java/de/ugoe/cs/autoquest/usability/AbstractUsabilityEvaluationTC.java

    r927 r1210  
    1616 
    1717import static org.junit.Assert.assertEquals; 
     18import static org.junit.Assert.assertTrue; 
    1819import static org.junit.Assert.fail; 
    1920 
    2021import java.util.ArrayList; 
     22import java.util.List; 
    2123import java.util.logging.Level; 
    22 import java.util.regex.Matcher; 
    23 import java.util.regex.Pattern; 
    2424 
    2525import org.junit.Before; 
    2626 
    27 import de.ugoe.cs.autoquest.eventcore.Event; 
    28 import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 
    29 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
    31 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 
    32 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    33 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree; 
    34 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeBuilder; 
    35 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode; 
    36 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNodeFactory; 
    37 import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskTreeBuilder; 
    38 import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskTreeNodeFactory; 
    39 import de.ugoe.cs.autoquest.test.DummyGUIElement; 
    40 import de.ugoe.cs.autoquest.test.DummyInteraction; 
    41 import de.ugoe.cs.autoquest.test.DummyTextField; 
    42 import de.ugoe.cs.autoquest.usability.UsabilityDefect; 
    43 import de.ugoe.cs.autoquest.usability.UsabilityEvaluationResult; 
     27import de.ugoe.cs.autoquest.tasktrees.TaskTreeDecoder; 
     28import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
     29import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; 
     30import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; 
     31import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 
     32import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
     33import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskBuilder; 
     34import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskFactory; 
    4435import de.ugoe.cs.util.console.TextConsole; 
    4536 
     
    5344 
    5445    /** */ 
    55     private ITaskTreeBuilder taskTreeBuilder = new TaskTreeBuilder(); 
     46    private ITaskBuilder taskBuilder = new TaskBuilder(); 
    5647 
    5748    /** */ 
    58     private ITaskTreeNodeFactory taskTreeNodeFactory = new TaskTreeNodeFactory(); 
     49    private ITaskFactory taskFactory = new TaskFactory(); 
    5950 
    6051    /** 
     
    6960   * 
    7061   */ 
    71     protected ITaskTree createTaskTree(String spec) { 
    72         Matcher matcher = 
    73             Pattern.compile("(\\s*(\\w+)\\s*(\\(((\\w*\\s*)*)\\))?\\s*(\\{))|(\\})").matcher(spec); 
     62    protected ITaskModel createTaskModel(String spec) { 
     63        TaskTreeDecoder decoder = new TaskTreeDecoder(taskFactory, taskBuilder); 
     64         
     65        ITaskInstanceList list = decoder.decode(spec); 
     66         
     67        assertTrue(list instanceof IUserSession); 
     68         
     69        List<IUserSession> sessions = new ArrayList<IUserSession>(); 
     70        sessions.add((IUserSession) list); 
    7471 
    75         if (!matcher.find()) { 
    76             if (!matcher.hitEnd()) { 
    77                 throw new IllegalArgumentException("could not parse task specification"); 
    78             } 
    79         } 
    80  
    81         return taskTreeNodeFactory.createTaskTree(parseTask(matcher, new int[1])); 
     72        return taskFactory.createTaskModel(sessions); 
    8273    } 
    8374 
     
    110101    } 
    111102 
    112     /** 
    113    *  
    114    */ 
    115     private ITaskTreeNode parseTask(Matcher tokenMatcher, int[] typeNumbers) { 
    116         String firstToken = tokenMatcher.group(); 
    117  
    118         if ("}".equals(firstToken)) { 
    119             throw new IllegalArgumentException("found a closing bracket at an unexpected place"); 
    120         } 
    121  
    122         ITaskTreeNode treeNode = instantiateTreeNode(tokenMatcher, typeNumbers); 
    123  
    124         if (!tokenMatcher.find()) { 
    125             throw new IllegalArgumentException("could not parse task specification"); 
    126         } 
    127  
    128         firstToken = tokenMatcher.group(); 
    129  
    130         if (!"}".equals(firstToken)) { 
    131             ITaskTreeNode child = null; 
    132  
    133             do { 
    134                 child = parseTask(tokenMatcher, typeNumbers); 
    135  
    136                 if (child != null) { 
    137                     addChild(treeNode, child); 
    138  
    139                     if (!tokenMatcher.find()) { 
    140                         throw new IllegalArgumentException("could not parse task specification"); 
    141                     } 
    142  
    143                     firstToken = tokenMatcher.group(); 
    144  
    145                     if ("}".equals(firstToken)) { 
    146                         break; 
    147                     } 
    148                 } 
    149  
    150             } 
    151             while (child != null); 
    152  
    153         } 
    154  
    155         return treeNode; 
    156     } 
    157  
    158     /** 
    159      * TODO: comment 
    160      *  
    161      * @param group 
    162      * @return 
    163      */ 
    164     private ITaskTreeNode instantiateTreeNode(Matcher tokenMatcher, int[] typeNumbers) { 
    165         String type = tokenMatcher.group(2); 
    166         String additionalInfo = tokenMatcher.group(4); 
    167  
    168         if ("Interaction".equals(type)) { 
    169             return taskTreeNodeFactory.createNewEventTask 
    170                 (new DummyInteraction("dummy", typeNumbers[0]++), new DummyGUIElement("dummy")); 
    171         } 
    172         else if ("Sequence".equals(type)) { 
    173             return taskTreeNodeFactory.createNewSequence(); 
    174         } 
    175         else if ("Iteration".equals(type)) { 
    176             return taskTreeNodeFactory.createNewIteration(); 
    177         } 
    178         else if ("Selection".equals(type)) { 
    179             return taskTreeNodeFactory.createNewSelection(); 
    180         } 
    181         else if ("TextInput".equals(type)) { 
    182             if (additionalInfo == null) { 
    183                 fail("no simulated text provided for text input interactin task"); 
    184             } 
    185  
    186             TextInput textInput = new TextInput(additionalInfo, new ArrayList<Event>()); 
    187              
    188             IEventTask task = taskTreeNodeFactory.createNewEventTask 
    189                 (textInput, new DummyTextField(additionalInfo)); 
    190  
    191             return task; 
    192         } 
    193         else { 
    194             fail("invalid type of task tree node: " + type); 
    195             return null; 
    196         } 
    197     } 
    198  
    199     /** 
    200      * TODO: comment 
    201      *  
    202      * @param treeNode 
    203      * @param child 
    204      */ 
    205     private void addChild(ITaskTreeNode parent, ITaskTreeNode child) { 
    206         if (parent instanceof ISequence) { 
    207             taskTreeBuilder.addChild((ISequence) parent, child); 
    208         } 
    209         else if (parent instanceof IIteration) { 
    210             if (parent.getChildren().size() <= 0) { 
    211                 taskTreeBuilder.setChild((IIteration) parent, child); 
    212             } 
    213             else { 
    214                 fail("can not add more than one child to an iteration"); 
    215             } 
    216         } 
    217         else if (parent instanceof ISelection) { 
    218             taskTreeBuilder.addChild((ISelection) parent, child); 
    219         } 
    220         else { 
    221             fail("can not add children to parent task tree node of type " + 
    222                  parent.getClass().getName()); 
    223         } 
    224     } 
    225  
    226103} 
  • trunk/autoquest-core-usability-test/src/test/java/de/ugoe/cs/autoquest/usability/TextInputStatisticsRuleTest.java

    r927 r1210  
    2626 
    2727import de.ugoe.cs.autoquest.usability.UsabilityDefect; 
    28 import de.ugoe.cs.autoquest.usability.UsabilityDefectDescription; 
    2928import de.ugoe.cs.autoquest.usability.UsabilityEvaluationManager; 
    3029 
     
    4746        // ===== check ===== 
    4847        String spec = 
    49             "TextInput (bla) {}"; 
     48            "UserSession {" + 
     49            "  TextInput (bla) {}" + 
     50            "}"; 
    5051        UsabilityDefect[] expectedDefects = new UsabilityDefect[] 
    5152            { new UsabilityDefect(HIGH, TEXT_FIELD_INPUT_RATIO) }; 
    5253 
    5354        assertUsabilityEvaluationResult 
    54             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
    55  
    56         // ===== check ===== 
    57         spec = 
    58             "Sequence {" + 
    59             "  TextInput (bla) {}" + 
    60             "}"; 
    61  
    62         expectedDefects = new UsabilityDefect[] 
    63             { new UsabilityDefect(HIGH, UsabilityDefectDescription.TEXT_FIELD_INPUT_RATIO) }; 
    64  
    65         assertUsabilityEvaluationResult 
    66             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
    67  
    68         // ===== check ===== 
    69         spec = 
    70             "Sequence {" + 
     55            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
     56 
     57        // ===== check ===== 
     58        spec = 
     59            "UserSession {" + 
    7160            "  TextInput (a) {}" + 
    7261            "  TextInput (b) {}" + 
     
    7968 
    8069        assertUsabilityEvaluationResult 
    81             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
    82  
    83         // ===== check ===== 
    84         spec = 
    85             "Selection {" + 
     70            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
     71 
     72        // ===== check ===== 
     73        spec = 
     74            "UserSession {" + 
    8675            "  TextInput (a) {}" + 
    8776            "  TextInput (b) {}" + 
     
    9483 
    9584        assertUsabilityEvaluationResult 
    96             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     85            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    9786 
    9887        // ===== check ===== 
     
    10695 
    10796        assertUsabilityEvaluationResult 
    108             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     97            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    10998 
    11099        // ===== check ===== 
     
    173162 
    174163        assertUsabilityEvaluationResult 
    175             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     164            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    176165    } 
    177166 
     
    198187 
    199188        assertUsabilityEvaluationResult 
    200             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     189            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    201190 
    202191        // ===== check ===== 
     
    214203 
    215204        assertUsabilityEvaluationResult 
    216             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     205            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    217206 
    218207        // ===== check ===== 
     
    229218 
    230219        assertUsabilityEvaluationResult 
    231             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     220            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    232221 
    233222        // ===== check ===== 
     
    245234 
    246235        assertUsabilityEvaluationResult 
    247             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     236            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    248237 
    249238        // ===== check ===== 
     
    326315 
    327316        assertUsabilityEvaluationResult 
    328             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     317            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    329318 
    330319        // ===== check ===== 
     
    407396 
    408397        assertUsabilityEvaluationResult 
    409             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     398            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    410399    } 
    411400 
     
    455444 
    456445        assertUsabilityEvaluationResult 
    457             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     446            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    458447 
    459448        // ===== check ===== 
     
    494483 
    495484        assertUsabilityEvaluationResult 
    496             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     485            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    497486 
    498487        // ===== check ===== 
     
    533522 
    534523        assertUsabilityEvaluationResult 
    535             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     524            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    536525 
    537526        // ===== check ===== 
     
    572561 
    573562        assertUsabilityEvaluationResult 
    574             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     563            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    575564 
    576565        // ===== check ===== 
     
    590579 
    591580        assertUsabilityEvaluationResult 
    592             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     581            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    593582 
    594583        // ===== check ===== 
     
    608597 
    609598        assertUsabilityEvaluationResult 
    610             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     599            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    611600 
    612601        // ===== check ===== 
     
    626615 
    627616        assertUsabilityEvaluationResult 
    628             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     617            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    629618 
    630619    } 
     
    649638 
    650639        assertUsabilityEvaluationResult 
    651             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     640            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    652641 
    653642        // ===== check ===== 
     
    662651 
    663652        assertUsabilityEvaluationResult 
    664             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     653            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    665654 
    666655        // ===== check ===== 
     
    675664 
    676665        assertUsabilityEvaluationResult 
    677             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     666            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    678667 
    679668        // ===== check ===== 
     
    689678 
    690679        assertUsabilityEvaluationResult 
    691             (expectedDefects, manager.evaluateUsability(createTaskTree(spec))); 
     680            (expectedDefects, manager.evaluateUsability(createTaskModel(spec))); 
    692681 
    693682    } 
Note: See TracChangeset for help on using the changeset viewer.