Skip to content

Commit d17743f

Browse files
mmercesdesimone
authored andcommitted
Reestructuring tests to allow travis processing them
1 parent d7e9813 commit d17743f

File tree

2 files changed

+207
-14
lines changed

2 files changed

+207
-14
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ script:
1313
- cd tests
1414
- export TESTS=$(for t in $BML_TESTS; do ls *$t*.php;done|paste -sd " ")
1515
- echo $TESTS
16-
- for t in $TESTS; do travis_wait 30 phpunit $t;done
16+
- for t in $TESTS; do travis_wait 30 phpunit --debug $t;done

tests/test_36_compare_predictions.php

+206-13
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class BigMLTestDeepnets extends PHPUnit_Framework_TestCase
2323
protected static $project;
2424

2525
public static function setUpBeforeClass() {
26-
print __FILE__;
26+
print __FILE__;
2727
self::$api = new BigML(self::$username, self::$api_key, false);
2828
ini_set('memory_limit', '5120M');
2929
$test_name=basename(preg_replace('/\.php$/', '', __FILE__));
@@ -37,12 +37,6 @@ public static function tearDownAfterClass() {
3737

3838
public function test_scenario1() {
3939

40-
$data2 = array(array("filename" => "data/iris.csv",
41-
"data_input" => array("petal width" => 4),
42-
"objective" => "000004",
43-
"prediction" => "Iris-virginica",
44-
"params" => array()));
45-
4640
$data = array(array("filename" => "data/iris.csv",
4741
"data_input" => array("petal width" => 4),
4842
"objective" => "000004",
@@ -53,8 +47,74 @@ public function test_scenario1() {
5347
"sepal width" => 2.4),
5448
"objective" => "000004",
5549
"prediction" => "Iris-setosa",
56-
"params" => array()),
57-
array("filename" => "data/iris_missing2.csv",
50+
"params" => array()));
51+
52+
foreach($data as $item) {
53+
print "\n\nSuccessfully comparing predictions for deepnets:\n";
54+
print "Given I create a data source uploading a " . $item["filename"] . " file\n";
55+
$source = self::$api->create_source($item["filename"], $options=array('name'=>'local_test_source', 'project'=> self::$project->resource));
56+
$this->assertEquals(BigMLRequest::HTTP_CREATED, $source->code);
57+
$this->assertEquals(1, $source->object->status->code);
58+
59+
print "And I wait until the source is ready\n";
60+
$resource = self::$api->_check_resource($source->resource, null, 3000, 30);
61+
$this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
62+
63+
if (isset($item["update_params"])) {
64+
print "And I update the source\n";
65+
$source = self::$api->update_source($source->resource, $item["update_params"], 3000, 30);
66+
}
67+
68+
print "And I create a dataset\n";
69+
$dataset = self::$api->create_dataset($source->resource);
70+
$this->assertEquals(BigMLRequest::HTTP_CREATED, $dataset->code);
71+
$this->assertEquals(BigMLRequest::QUEUED, $dataset->object->status->code);
72+
73+
print "And I wait until the dataset is ready\n";
74+
$resource = self::$api->_check_resource($dataset->resource, null, 3000, 30);
75+
$this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
76+
77+
print "And I create a deepnet with objective " . $item["objective"] .
78+
" and " . json_encode($item["params"]) . "\n";
79+
$deepnet = self::$api->create_deepnet($dataset->resource, $item["params"]);
80+
$this->assertEquals(BigMLRequest::HTTP_CREATED, $deepnet->code);
81+
82+
print "And I wait until the deepnet is ready\n";
83+
$resource = self::$api->_check_resource($deepnet->resource, null, 3000, 500);
84+
$this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
85+
86+
print "And I create a local deepnet\n";
87+
$local_deepnet = new Deepnet($deepnet->resource);
88+
89+
print "And I create a deepnet prediction\n";
90+
$prediction = self::$api->create_prediction($deepnet->resource, $item["data_input"]);
91+
92+
print "The prediction is ";
93+
$prediction_value = $prediction->object->prediction->$item["objective"];
94+
print_r($prediction_value);
95+
96+
97+
print "\nAnd I create a local deepnet prediction\n";
98+
$local_prediction = $local_deepnet->predict($item["data_input"]);
99+
100+
if (is_array($local_prediction["prediction"])) {
101+
$local_prediction = $local_prediction["prediction"];
102+
} else {
103+
$prediction_value = round($prediction_value, 5);
104+
$local_prediction = round($local_prediction, 5);
105+
}
106+
107+
print "The local prediction is ";
108+
print_r($local_prediction);
109+
$this->assertEquals($prediction_value,
110+
$local_prediction);
111+
112+
}
113+
}
114+
115+
public function test_scenario2() {
116+
117+
$data = array(array("filename" => "data/iris_missing2.csv",
58118
"data_input" => array(),
59119
"objective" => "000004",
60120
"prediction" => "Iris-setosa",
@@ -72,8 +132,74 @@ public function test_scenario1() {
72132
"case_sensitive" => true,
73133
"stem_words" => true,
74134
"use_stopwords" => false,
75-
"language" => "en"))))),
76-
array("filename" => "data/iris.csv",
135+
"language" => "en"))))));
136+
137+
foreach($data as $item) {
138+
print "\n\nSuccessfully comparing predictions for deepnets:\n";
139+
print "Given I create a data source uploading a " . $item["filename"] . " file\n";
140+
$source = self::$api->create_source($item["filename"], $options=array('name'=>'local_test_source', 'project'=> self::$project->resource));
141+
$this->assertEquals(BigMLRequest::HTTP_CREATED, $source->code);
142+
$this->assertEquals(1, $source->object->status->code);
143+
144+
print "And I wait until the source is ready\n";
145+
$resource = self::$api->_check_resource($source->resource, null, 3000, 30);
146+
$this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
147+
148+
if (isset($item["update_params"])) {
149+
print "And I update the source\n";
150+
$source = self::$api->update_source($source->resource, $item["update_params"], 3000, 30);
151+
}
152+
153+
print "And I create a dataset\n";
154+
$dataset = self::$api->create_dataset($source->resource);
155+
$this->assertEquals(BigMLRequest::HTTP_CREATED, $dataset->code);
156+
$this->assertEquals(BigMLRequest::QUEUED, $dataset->object->status->code);
157+
158+
print "And I wait until the dataset is ready\n";
159+
$resource = self::$api->_check_resource($dataset->resource, null, 3000, 30);
160+
$this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
161+
162+
print "And I create a deepnet with objective " . $item["objective"] .
163+
" and " . json_encode($item["params"]) . "\n";
164+
$deepnet = self::$api->create_deepnet($dataset->resource, $item["params"]);
165+
$this->assertEquals(BigMLRequest::HTTP_CREATED, $deepnet->code);
166+
167+
print "And I wait until the deepnet is ready\n";
168+
$resource = self::$api->_check_resource($deepnet->resource, null, 3000, 500);
169+
$this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
170+
171+
print "And I create a local deepnet\n";
172+
$local_deepnet = new Deepnet($deepnet->resource);
173+
174+
print "And I create a deepnet prediction\n";
175+
$prediction = self::$api->create_prediction($deepnet->resource, $item["data_input"]);
176+
177+
print "The prediction is ";
178+
$prediction_value = $prediction->object->prediction->$item["objective"];
179+
print_r($prediction_value);
180+
181+
182+
print "\nAnd I create a local deepnet prediction\n";
183+
$local_prediction = $local_deepnet->predict($item["data_input"]);
184+
185+
if (is_array($local_prediction["prediction"])) {
186+
$local_prediction = $local_prediction["prediction"];
187+
} else {
188+
$prediction_value = round($prediction_value, 5);
189+
$local_prediction = round($local_prediction, 5);
190+
}
191+
192+
print "The local prediction is ";
193+
print_r($local_prediction);
194+
$this->assertEquals($prediction_value,
195+
$local_prediction);
196+
197+
}
198+
}
199+
200+
public function test_scenario3() {
201+
202+
$data = array(array("filename" => "data/iris.csv",
77203
"data_input" => array("sepal length" => 4.1,
78204
"sepal width" => 2.4),
79205
"objective" => "000004",
@@ -92,8 +218,75 @@ public function test_scenario1() {
92218
"separator" => "\$")))),
93219
"objective" => "000009",
94220
"prediction" => "4.49741",
95-
"params" => array()),
96-
array("filename" => "data/movies.csv",
221+
"params" => array()));
222+
223+
foreach($data as $item) {
224+
print "\n\nSuccessfully comparing predictions for deepnets:\n";
225+
print "Given I create a data source uploading a " . $item["filename"] . " file\n";
226+
$source = self::$api->create_source($item["filename"], $options=array('name'=>'local_test_source', 'project'=> self::$project->resource));
227+
$this->assertEquals(BigMLRequest::HTTP_CREATED, $source->code);
228+
$this->assertEquals(1, $source->object->status->code);
229+
230+
print "And I wait until the source is ready\n";
231+
$resource = self::$api->_check_resource($source->resource, null, 3000, 30);
232+
$this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
233+
234+
if (isset($item["update_params"])) {
235+
print "And I update the source\n";
236+
$source = self::$api->update_source($source->resource, $item["update_params"], 3000, 30);
237+
}
238+
239+
print "And I create a dataset\n";
240+
$dataset = self::$api->create_dataset($source->resource);
241+
$this->assertEquals(BigMLRequest::HTTP_CREATED, $dataset->code);
242+
$this->assertEquals(BigMLRequest::QUEUED, $dataset->object->status->code);
243+
244+
print "And I wait until the dataset is ready\n";
245+
$resource = self::$api->_check_resource($dataset->resource, null, 3000, 30);
246+
$this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
247+
248+
print "And I create a deepnet with objective " . $item["objective"] .
249+
" and " . json_encode($item["params"]) . "\n";
250+
$deepnet = self::$api->create_deepnet($dataset->resource, $item["params"]);
251+
$this->assertEquals(BigMLRequest::HTTP_CREATED, $deepnet->code);
252+
253+
print "And I wait until the deepnet is ready\n";
254+
$resource = self::$api->_check_resource($deepnet->resource, null, 3000, 500);
255+
$this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
256+
257+
print "And I create a local deepnet\n";
258+
$local_deepnet = new Deepnet($deepnet->resource);
259+
260+
print "And I create a deepnet prediction\n";
261+
$prediction = self::$api->create_prediction($deepnet->resource, $item["data_input"]);
262+
263+
print "The prediction is ";
264+
$prediction_value = $prediction->object->prediction->$item["objective"];
265+
print_r($prediction_value);
266+
267+
268+
print "\nAnd I create a local deepnet prediction\n";
269+
$local_prediction = $local_deepnet->predict($item["data_input"]);
270+
271+
if (is_array($local_prediction["prediction"])) {
272+
$local_prediction = $local_prediction["prediction"];
273+
} else {
274+
$prediction_value = round($prediction_value, 5);
275+
$local_prediction = round($local_prediction, 5);
276+
}
277+
278+
print "The local prediction is ";
279+
print_r($local_prediction);
280+
$this->assertEquals($prediction_value,
281+
$local_prediction);
282+
283+
}
284+
}
285+
286+
287+
public function test_scenario4() {
288+
289+
$data = array(array("filename" => "data/movies.csv",
97290
"data_input" => array("genres" => "Adventure\$Action",
98291
"timestamp" => 993906291,
99292
"occupation" => "K-12 student"),

0 commit comments

Comments
 (0)