From 29031842c0ac7e48a4abc2384d55bd67ae202097 Mon Sep 17 00:00:00 2001 From: Michael Larabel Date: Mon, 17 Nov 2008 14:00:36 -0500 Subject: pts-core: Branch out classes from pts-generic-classes.php --- pts-core/objects/pts_test_result.php | 207 +++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 pts-core/objects/pts_test_result.php (limited to 'pts-core/objects/pts_test_result.php') diff --git a/pts-core/objects/pts_test_result.php b/pts-core/objects/pts_test_result.php new file mode 100644 index 0000000..8d9619a --- /dev/null +++ b/pts-core/objects/pts_test_result.php @@ -0,0 +1,207 @@ +. +*/ + +class pts_test_result +{ + var $result; + var $result_scale; + var $result_format; + var $result_proportion; + var $result_quantifier; + var $trial_results; + var $attributes; + + public function __construct($result = 0, $result_scale = "", $result_format = "") + { + $this->result = $result; + $this->result_scale = $result_scale; + $this->result_format = $result_format; + + $this->trial_results = array(); + $this->attributes = array(); + $this->result_quantifier = null; + $this->result_proportion = null; + } + public function set_result($result) + { + $this->result = $result; + } + public function set_result_scale($result_scale) + { + $this->result_scale = $result_scale; + } + public function set_result_format($result_format) + { + $this->result_format = $result_format; + } + public function set_result_proportion($result_proportion) + { + $this->result_proportion = $result_proportion; + } + public function set_result_quantifier($result_quantifier) + { + $this->result_quantifier = $result_quantifier; + } + public function set_attribute($name, $value) + { + $this->attributes[$name] = $value; + } + public function get_result() + { + return $this->result; + } + public function get_result_scale() + { + return $this->result_scale; + } + public function get_result_format() + { + return $this->result_format; + } + public function get_result_proportion() + { + return $this->result_proportion; + } + public function get_attribute($name) + { + if(isset($this->attributes[$name]) && !empty($this->attributes[$name])) + { + return $this->attributes[$name]; + } + } + public function add_trial_run_result($result) + { + if(!empty($result)) + { + array_push($this->trial_results, $result); + } + } + public function calculate_end_result(&$return_string) + { + $END_RESULT = 0; + if($this->result_format == "NO_RESULT") + { + // Nothing to do + $return_string = null; + } + else if($this->result_format == "PASS_FAIL" || $this->result_format == "MULTI_PASS_FAIL") + { + // Calculate pass/fail type + $return_string .= "(" . $this->result_scale . ")\n"; + $END_RESULT = -1; + $i = 1; + + if(count($this->trial_results) == 1) + { + $END_RESULT = $this->trial_results[0]; + } + else + { + foreach($this->trial_results as $result) + { + if($result == "FALSE" || $result == "0" || $result == "FAIL") + { + $this_result = "FAIL"; + + if($END_RESULT == -1 || $END_RESULT == "PASS") + { + $END_RESULT = "FAIL"; + } + } + else + { + $this_result = "PASS"; + + if($END_RESULT == -1) + { + $END_RESULT = "PASS"; + } + } + + $return_string .= "Trial $i: " . $this_result . "\n"; + $i++; + } + } + + $return_string .= "\nFinal: " . $END_RESULT . "\n"; + } + else + { + // Result is of a normal numerical type + + if($this->result_quantifier == "MAX") + { + $max_value = $this->trial_results[0]; + foreach($this->trial_results as $result) + { + if($result > $max_value) + { + $max_value = $result; + } + + $return_string .= $result . " " . $this->result_scale . "\n"; + } + $return_string .= "\nMaximum: " . $max_value . " " . $this->result_scale; + $END_RESULT = $max_value; + } + else if($this->result_quantifier == "MIN") + { + $min_value = $this->trial_results[0]; + foreach($this->trial_results as $result) + { + if($result < $min_value) + { + $min_value = $result; + } + + $return_string .= $result . " " . $this->result_scale . "\n"; + } + $return_string .= "\nMinimum: " . $min_value . " " . $this->result_scale; + $END_RESULT = $min_value; + } + else + { + // assume AVG (average) + $TOTAL_RESULT = 0; + foreach($this->trial_results as $result) + { + $TOTAL_RESULT += trim($result); + $return_string .= $result . " " . $this->result_scale . "\n"; + } + + if(count($this->trial_results) > 0) + { + $END_RESULT = pts_trim_double($TOTAL_RESULT / count($this->trial_results), 2); + } + else + { + $END_RESULT = pts_trim_double($TOTAL_RESULT, 2); + } + + $return_string .= "\nAverage: " . $END_RESULT . " " . $this->result_scale; + } + } + $this->set_result($END_RESULT); + } +} + +?> -- cgit