Skip to content

Commit

Permalink
Use assertCount in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas committed Dec 12, 2016
1 parent b6fe290 commit a78ebc1
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions tests/Phpml/Clustering/KMeansTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public function testKMeansSamplesClustering()
$kmeans = new KMeans(2);
$clusters = $kmeans->cluster($samples);

$this->assertEquals(2, count($clusters));
$this->assertCount(2, $clusters);

foreach ($samples as $index => $sample) {
if (in_array($sample, $clusters[0]) || in_array($sample, $clusters[1])) {
unset($samples[$index]);
}
}
$this->assertEquals(0, count($samples));
$this->assertCount(0, $samples);
}

public function testKMeansInitializationMethods()
Expand All @@ -42,11 +42,11 @@ public function testKMeansInitializationMethods()

$kmeans = new KMeans(4, KMeans::INIT_KMEANS_PLUS_PLUS);
$clusters = $kmeans->cluster($samples);
$this->assertEquals(4, count($clusters));
$this->assertCount(4, $clusters);

$kmeans = new KMeans(4, KMeans::INIT_RANDOM);
$clusters = $kmeans->cluster($samples);
$this->assertEquals(4, count($clusters));
$this->assertCount(4, $clusters);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Phpml/CrossValidation/RandomSplitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public function testDatasetRandomSplitWithoutSeed()

$randomSplit = new RandomSplit($dataset, 0.5);

$this->assertEquals(2, count($randomSplit->getTestSamples()));
$this->assertEquals(2, count($randomSplit->getTrainSamples()));
$this->assertCount(2, $randomSplit->getTestSamples());
$this->assertCount(2, $randomSplit->getTrainSamples());

$randomSplit2 = new RandomSplit($dataset, 0.25);

$this->assertEquals(1, count($randomSplit2->getTestSamples()));
$this->assertEquals(3, count($randomSplit2->getTrainSamples()));
$this->assertCount(1, $randomSplit2->getTestSamples());
$this->assertCount(3, $randomSplit2->getTrainSamples());
}

public function testDatasetRandomSplitWithSameSeed()
Expand Down
8 changes: 4 additions & 4 deletions tests/Phpml/Dataset/CsvDatasetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function testSampleCsvDatasetWithHeaderRow()

$dataset = new CsvDataset($filePath, 2, true);

$this->assertEquals(10, count($dataset->getSamples()));
$this->assertEquals(10, count($dataset->getTargets()));
$this->assertCount(10, $dataset->getSamples());
$this->assertCount(10, $dataset->getTargets());
}

public function testSampleCsvDatasetWithoutHeaderRow()
Expand All @@ -32,7 +32,7 @@ public function testSampleCsvDatasetWithoutHeaderRow()

$dataset = new CsvDataset($filePath, 2, false);

$this->assertEquals(11, count($dataset->getSamples()));
$this->assertEquals(11, count($dataset->getTargets()));
$this->assertCount(11, $dataset->getSamples());
$this->assertCount(11, $dataset->getTargets());
}
}
6 changes: 3 additions & 3 deletions tests/Phpml/Dataset/Demo/GlassDatasetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public function testLoadingWineDataset()
$glass = new GlassDataset();

// whole dataset
$this->assertEquals(214, count($glass->getSamples()));
$this->assertEquals(214, count($glass->getTargets()));
$this->assertCount(214, $glass->getSamples());
$this->assertCount(214, $glass->getTargets());

// one sample features count
$this->assertEquals(9, count($glass->getSamples()[0]));
$this->assertCount(9, $glass->getSamples()[0]);
}
}
6 changes: 3 additions & 3 deletions tests/Phpml/Dataset/Demo/IrisDatasetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public function testLoadingIrisDataset()
$iris = new IrisDataset();

// whole dataset
$this->assertEquals(150, count($iris->getSamples()));
$this->assertEquals(150, count($iris->getTargets()));
$this->assertCount(150, $iris->getSamples());
$this->assertCount(150, $iris->getTargets());

// one sample features count
$this->assertEquals(4, count($iris->getSamples()[0]));
$this->assertCount(4, $iris->getSamples()[0]);
}
}
6 changes: 3 additions & 3 deletions tests/Phpml/Dataset/Demo/WineDatasetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public function testLoadingWineDataset()
$wine = new WineDataset();

// whole dataset
$this->assertEquals(178, count($wine->getSamples()));
$this->assertEquals(178, count($wine->getTargets()));
$this->assertCount(178, $wine->getSamples());
$this->assertCount(178, $wine->getTargets());

// one sample features count
$this->assertEquals(13, count($wine->getSamples()[0]));
$this->assertCount(13, $wine->getSamples()[0]);
}
}
4 changes: 2 additions & 2 deletions tests/Phpml/Dataset/FilesDatasetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function testLoadFilesDatasetWithBBCData()

$dataset = new FilesDataset($rootPath);

$this->assertEquals(50, count($dataset->getSamples()));
$this->assertEquals(50, count($dataset->getTargets()));
$this->assertCount(50, $dataset->getSamples());
$this->assertCount(50, $dataset->getTargets());

$targets = ['business', 'entertainment', 'politics', 'sport', 'tech'];
$this->assertEquals($targets, array_values(array_unique($dataset->getTargets())));
Expand Down
4 changes: 2 additions & 2 deletions tests/Phpml/Math/SetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testPower()

$this->assertInternalType('array', $power);
$this->assertEquals([new Set(), new Set(['A']), new Set(['B']), new Set(['A', 'B'])], $power);
$this->assertEquals(4, count($power));
$this->assertCount(4, $power);
}

public function testCartesian()
Expand All @@ -48,7 +48,7 @@ public function testCartesian()

$this->assertInternalType('array', $cartesian);
$this->assertEquals([new Set(['A', 1]), new Set(['A', 2])], $cartesian);
$this->assertEquals(2, count($cartesian));
$this->assertCount(2, $cartesian);
}

public function testContains()
Expand Down

0 comments on commit a78ebc1

Please sign in to comment.