예제 #1
0
 def next_test_instruction(self):
     if self.next_step % 2 == 0:
         # provide a new input (step/2+1)-th input (starting with 1)
         return Input(self.active_test(int(self.next_step / 2) + 1))
     else:
         return Output(
             None)  # here, this means that an output should be expected
    def get_traces(self, boundary):
        # check if values are already computed
        if self.values_k_1 == None or self.values_k_2 == None or len(
                self.values_k_1) != boundary or len(
                    self.values_k_2) != boundary:

            # inputs are all natural numbers
            inputs = xrange(1, boundary + 1)

            # create the empty trace for k=1 and k=2 in the computation algorithm
            self.values_k_1 = SimpleTrace(
                [], boundary
            )  # Note that we do not use the boundary functionality of the trace here, because we generate the trace of the aprropriate size directly
            self.values_k_2 = SimpleTrace([], boundary)

            number_of_items = 0

            for inp in inputs:
                # add the current input
                self.values_k_1.extend(Input(float(inp)))
                self.values_k_2.extend(Input(float(inp)))

                number_of_items = number_of_items + 1
                if number_of_items >= boundary:
                    # We added enough values (note that the for-loop without the breaks would produce 2*boundary values)
                    break

                # add the corresponding output
                self.values_k_1.extend(Output(float(inp) * 1))  # o = i * 1
                self.values_k_2.extend(Output(float(inp) * 2))  # o = i * 2

                number_of_items = number_of_items + 1
                if number_of_items >= boundary:
                    break

        return [self.values_k_2, self.values_k_1]
    def receive_output(self):
        # get the output from the recordedTrace
        next_symbol = self.recordedTrace.get_current_symbol()

        # reassure that it is an output
        if isinstance(next_symbol, Output):
            # advance the internal symbol position of the recordedTrace to the next symbol
            self.recordedTrace.advance_symbol()
            return next_symbol
        else:
            # if the symbol is not an output, warn the user and return quiescence
            print(
                'Warning! DT requested an output although no output is available.'
            )
            return Output(None)
    def get_symbol_from_string(self, str):
        if str[0] == 'i':
            # this is an input
            # parse the value
            number = float(str[1:])

            return Input(number)
        elif str[0] == 'o':
            # we have an output
            # parse the value
            number = float(str[1:])

            return Output(number)
        else:
            raise Exception('Unknown file format!')
예제 #5
0
 def wrong_test_instruction(self):
     if self.next_step == 2:
         return Output(None)
     else:
         return self.next_test_instruction()
예제 #6
0
    def advance(self):
        # pick one of the three options of the algorithm
        option = self.test_case_selection.get_next_option(self.history)

        if option == TestCaseSelection.OPTION_PASS:
            # the test is passed
            return TestResult(TestResult.PASSED, self.history)

        elif option == TestCaseSelection.OPTION_INPUT:
            # get the next input from test case selection
            next_input = self.test_case_selection.get_next_input(self.history)

            # pass input to SUT and check if SUT provided an output in the meantime
            system_output = self.system_under_test.pass_input(next_input)

            if system_output != None:
                # the input is cancelled, because the output generated by the SUT must be processed first.
                # the new output may influence test case selection

                # we add the output to the history
                self.history.extend(system_output)

                # Check if the output is accepted (this is the case, if no counter example can be found)
                counterexample = self.output_verifier.check_output(
                    self.history)

                if counterexample != None:
                    # the test failed, because we received an invalid output
                    return TestResult(TestResult.FAILED, self.history,
                                      counterexample)

            else:  # system_output == None
                # the input has been accepted, so we add it to the history
                self.history.extend(next_input)

                # return None to indicate that the test is neither passed nor failed
                return None

        elif option == TestCaseSelection.OPTION_OUTPUT:
            # we wait for the next output or quiescence
            system_output = self.system_under_test.receive_output()

            if system_output == None:
                # we observe quiescence

                # we add the quiescence to the history
                self.history.extend(Output(None))

                # Check if quiescence is accepted (this is the case, if no counter example can be found)
                counterexample = self.output_verifier.check_quiescence(
                    self.history)

                if counterexample != None:
                    # the test failed, because quiescence is not allowed here
                    return TestResult(TestResult.FAILED, self.history,
                                      counterexample)

            else:
                # we add the verified output to the history
                self.history.extend(system_output)

                # Check if the output is accepted (this is the case, if no counter example can be found)
                counterexample = self.output_verifier.check_output(
                    self.history)

                if counterexample != None:
                    # the test failed, because we received an invalid output
                    return TestResult(TestResult.FAILED, self.history,
                                      counterexample)

            # return None to indicate that the test is neither passed nor failed
            return None

        else:
            raise Exception('Invalid option!')