public function testTransformToDFA() { //initizlize input $json = '{"stateNames":["A","B","C"],"transitions":["0","1"],"states":[{"name":"A","adjacencyList":{"0":["A","B"],"1":["C"]}},{"name":"B","adjacencyList":{"0":["C"],"1":[]}},{"name":"C","adjacencyList":{"0":[],"1":["B","C"]}}]}'; //decode JSON and extract contents $obj = json_decode($json); $stateNames = $obj->stateNames; $transitions = $obj->transitions; $nfaStates = jsonToStateArray($obj->states); //transform it $output = transformToDfa($stateNames, $transitions, $nfaStates); //Make sure all elements are the right expected output $this->assertEquals("ABC", $output["ABC"]->adjacencyList["0"]); $this->assertEquals("BC", $output["ABC"]->adjacencyList["1"]); $this->assertEquals("C", $output["BC"]->adjacencyList["0"]); $this->assertEquals("BC", $output["BC"]->adjacencyList["1"]); $this->assertEquals("@", $output["C"]->adjacencyList["0"]); $this->assertEquals("BC", $output["C"]->adjacencyList["1"]); $this->assertEquals("ABC", $output["AB"]->adjacencyList["0"]); $this->assertEquals("C", $output["AB"]->adjacencyList["1"]); $this->assertEquals("AB", $output["A"]->adjacencyList["0"]); $this->assertEquals("C", $output["A"]->adjacencyList["1"]); $this->assertEquals("@", $output["@"]->adjacencyList["0"]); $this->assertEquals("@", $output["@"]->adjacencyList["1"]); }
<?php require "state.php"; require "json.php"; // decode the json from the server $json = file_get_contents('php://input'); $obj = json_decode($json); // extract the contents of the json and feed them into the preprocessing functions $stateNames = $obj->stateNames; $transitions = $obj->transitions; $nfaStates = jsonToStateArray($obj->states); // perform the subset transformation and return to the client $dfaStates = transformToDfa($stateNames, $transitions, $nfaStates); echo buildJSON($dfaStates);