Package com.darkhonor.rage.model

Examples of com.darkhonor.rage.model.TestCase


                    // Parse test cases for each question
                    NodeList testCaseNodes = (NodeList) xpath.evaluate("./TestCase", q, XPathConstants.NODESET);
                    for (int j = 0; j < testCaseNodes.getLength(); j++)
                    {
                        TestCase tc = new TestCase();
                        Node t = testCaseNodes.item(j);
                        String value = xpath.evaluate("./Value/@value", t);
                        tc.setValue(new BigDecimal(value));
                        NodeList tcInputs = (NodeList) xpath.evaluate("./input", t, XPathConstants.NODESET);
                        for (int k = 0; k < tcInputs.getLength(); k++)
                        {
                            Node inputNode = tcInputs.item(k);
                            String input = inputNode.getTextContent();
                            //System.out.println("Input: " + input);
                            tc.addInput(input);
                        }
                        NodeList tcOutputs = (NodeList) xpath.evaluate("./output", t, XPathConstants.NODESET);
                        for (int k = 0; k < tcOutputs.getLength(); k++)
                        {
                            Node outputNode = tcOutputs.item(k);
                            String output = outputNode.getTextContent();
                            //System.out.println("Expected Output: " + output);
                            tc.addOutput(output);
                        }
                        NodeList tcExcludes = (NodeList) xpath.evaluate("./exclude", t, XPathConstants.NODESET);
                        for (int k = 0; k < tcExcludes.getLength(); k++)
                        {
                            Node outputNode = tcExcludes.item(k);
                            String exclude = outputNode.getTextContent();
                            //System.out.println("Exclusion: " + exclude);
                            tc.addExclusion(exclude);
                        }
                        tx.begin();
                        em.persist(tc);
                        tx.commit();
                        quest.addTestCase(tc);
View Full Code Here


                        {
                            int testCaseIndex = k + 1;
                            responseWriter.println("<tr>\n<td>" + testCaseIndex
                                    + "</td>");
                            responseWriter.println("<td><center>");
                            TestCase testCase = question.getTestCases().get(k);
                            for (int m = 0; m < testCase.getInputs().size(); m++)
                            {
                                responseWriter.println(testCase.getInputs().get(m)
                                        + "<br />");
                            }
                            responseWriter.println("</center></td>");
                            responseWriter.println("<td><center>");
                            for (int m = 0; m < testCase.getOutputs().size(); m++)
                            {
                                responseWriter.println(testCase.getOutputs().get(m)
                                        + "<br />");
                            }
                            responseWriter.println("</center></td>");
                            responseWriter.println("<td><center>");
                            Response response;
View Full Code Here

            // Thread variables to track the Question and our location in it
            Question question = new Question();
            // Initialize the iterator with some dummy (aka empty) data
            // Iterator will be properly initialized when the question has been picked
            Iterator tcIterator = question.getTestCases().iterator();
            TestCase tc = new TestCase();

            while (!done)
            {
                String line;
                try
                {
                    line = in.nextLine();
                } catch (NoSuchElementException exc)
                {
                    line = null;
                }
                if (line == null)
                {
                    done = true;
                } else
                {
                    if (!input_sent && line.trim().equalsIgnoreCase("DIRECTORY"))
                    {
                        for (int i = 0; i < question_names.size(); i++)
                        {
                            out.print(question_names.get(i) + "\r\n");
                            out.flush();
                        }
                        out.print("EOF\r\n");
                        out.flush();
                        done = true;
                    } else if (!input_sent
                            && question_names.contains(line.trim().toUpperCase()))
                    {
                        for (int i = 0; i < availQuestions.size(); i++)
                        {
                            Question q = availQuestions.get(i);
                            // We can set the question here because we know that
                            // the question exists on the server--we're in this
                            // block
                            if (q.getName().equalsIgnoreCase(line.trim()))
                            {
                                question = q;
                            }
                        }
                        /**
                         * The following code must be wrapped in a transaction
                         * since the application will query the database to return
                         * the list of test cases associated with the Question.
                         */
                        tx.begin();
                        LOGGER.debug("Found Question: " + question.getName());
                        numTestCases = question.getTestCases().size();
                        out.print(numTestCases + "\r\n");
                        out.flush();
                        tcMarker = 1;
                        // Reinitialize iterator with actual data
                        tcIterator = question.getTestCases().iterator();
                        tc = (TestCase) tcIterator.next();
                        for (int i = 0; i < tc.getInputs().size(); i++)
                        {
                            out.print(tc.getInputs().get(i) + "\r\n");
                            out.flush();
                        }
                        tx.commit();
                        /**
                         * End of Transaction
                         */
                        out.print("EOF\r\n");
                        out.flush();
                        input_sent = true;
                        if (tc.getExcludes().size() > 0)
                        {
                            exclusionsAvailable = true;
                        }
                    } else if ((input_sent) && !line.trim().equals("EOF"))
                    {
                        // Save the responses received to an array (don't
                        // persist at this time since these are not graded
                        if (!line.equals(""))
                        {
                            LOGGER.debug("Received: " + line.trim());
                            response.addAnswer(line.trim());
                        }
                    } else if ((input_sent) && line.trim().equals("EOF"))
                    {
                        // Evaluate the inputs received (stored in array) against
                        // the expected values stored in the database and send
                        // the appropriate response back to client
                        response.setResult(RageLib.gradeTestCase(tc, response,
                                question.getVerbatim(), exclusionsAvailable));
                        if (response.getResult())
                        {
                            out.print("CORRECT\r\n");
                            out.flush();
                            LOGGER.debug("Correct response received for "
                                    + question.getName());
                        } else
                        {
                            out.print("INCORRECT\r\n");
                            out.flush();
                            LOGGER.debug("Incorrect response received for "
                                    + question.getName());
                        }
                        if (numTestCases == tcMarker)
                        {
                            done = true;
                        } else
                        {
                            response.setResult(true);
                            tcMarker++;
                            input_sent = false;
                            /**
                             * The following code must be wrapped in a transaction
                             * since the application will query the database to return
                             * the list of inputs associated with the Test Case.
                             */
                            tx.begin();
                            tc = (TestCase) tcIterator.next();
                            for (int i = 0; i < tc.getInputs().size(); i++)
                            {
                                out.print(tc.getInputs().get(i) + "\r\n");
                                out.flush();
                            }
                            tx.commit();
                            /**
                             * End of Transaction
                             */
                            out.print("EOF\r\n");
                            out.flush();
                            input_sent = true;
                            response.clearAnswers();
                            exclusionsAvailable = false;
                            if (tc.getExcludes().size() > 0)
                            {
                                exclusionsAvailable = true;
                            }
                        }
                    } else
View Full Code Here

    public void testFind()
    {
        System.out.println("find");
        Long id = new Long(2L);
        BigDecimal expValue = new BigDecimal("2.5");
        TestCase expResult = createSampleTestCase2();

        assertTrue(instance.isOpen());
        TestCase result = instance.find(id);
        assertNotNull(result);
        assertEquals(id, result.getId());
        assertEquals(expValue, result.getValue());
        assertNotNull(result.getInputs());
        assertEquals(2, result.getInputs().size());
        assertNotNull(result.getOutputs());
        assertEquals(1, result.getOutputs().size());
        assertNotNull(result.getExcludes());
        assertEquals(0, result.getExcludes().size());
        assertEquals(expResult, result);
        assertTrue(instance.isOpen());
    }
View Full Code Here

    {
        System.out.println("find - No result");
        Long id = new Long(53L);

        assertTrue(instance.isOpen());
        TestCase result = instance.find(id);
        assertNull(result);
        assertTrue(instance.isOpen());
    }
View Full Code Here

        Long id = new Long(2L);

        assertTrue(instance.isOpen());
        instance.closeConnection();
        assertFalse(instance.isOpen());
        TestCase result = instance.find(id);
    }
View Full Code Here

    public void testFindIdEqualsZero()
    {
        System.out.println("find - id = 0");
        Long id = new Long(0L);
        assertTrue(instance.isOpen());
        TestCase result = instance.find(id);
    }
View Full Code Here

    public void testFindIdLessThanZero()
    {
        System.out.println("find - id < 0");
        Long id = new Long(-2L);
        assertTrue(instance.isOpen());
        TestCase result = instance.find(id);
    }
View Full Code Here

    public void testFindIdEqualsNull()
    {
        System.out.println("find - id = null");
        Long id = null;
        assertTrue(instance.isOpen());
        TestCase result = instance.find(id);
    }
View Full Code Here

     */
    @Test
    public void testCreate()
    {
        System.out.println("create");
        TestCase testCase = createNewTestCase();
        Long expResult = new Long(43L);
        assertTrue(instance.isOpen());
        Long result = instance.create(testCase);
        assertTrue(instance.isOpen());
        assertEquals(expResult, result);
       
        TestCase searchTestCase = instance.find(new Long(43L));
        assertNotNull(searchTestCase);
        assertEquals(new BigDecimal("10.35"), searchTestCase.getValue());
        assertEquals(1, searchTestCase.getInputs().size());
        assertEquals("42", searchTestCase.getInputs().get(0));
        assertEquals(1, searchTestCase.getOutputs().size());
        assertEquals("The Ultimate Answer", searchTestCase.getOutputs().get(0));
        assertEquals(1, searchTestCase.getExcludes().size());
        assertEquals("Question", searchTestCase.getExcludes().get(0));
    }
View Full Code Here

TOP

Related Classes of com.darkhonor.rage.model.TestCase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.