Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert unittests to use PHP 8 attributes #51

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/test/php/util/data/unittest/AggregationsTest.class.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php namespace util\data\unittest;

use unittest\Assert;
use unittest\{Assert, Test};
use util\data\{Aggregations, Sequence};

class AggregationsTest {

#[@test]
#[Test]
public function min_max_sum_average_and_count_for_empty_sequence() {
Sequence::$EMPTY
->collecting($min, Aggregations::min())
Expand All @@ -22,7 +22,7 @@ public function min_max_sum_average_and_count_for_empty_sequence() {
Assert::equals(0, $count);
}

#[@test]
#[Test]
public function min_max_sum_average_and_count_for_non_empty() {
Sequence::of([1, 2, 3, 4])
->collecting($min, Aggregations::min())
Expand Down
10 changes: 5 additions & 5 deletions src/test/php/util/data/unittest/BoundariesTest.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace util\data\unittest;

use unittest\Assert;
use unittest\{Assert, Test, Values};
use util\data\Sequence;
use util\{Comparator, Date};

Expand All @@ -19,25 +19,25 @@ private function comparators() {
yield [function($a, $b) { return $b->compareTo($a); }];
}

#[@test, @values('values')]
#[Test, Values('values')]
public function min($min, $max, $values) {
Assert::equals($min, Sequence::of($values)->min());
}

#[@test, @values('comparators')]
#[Test, Values('comparators')]
public function min_using($comparator) {
Assert::equals(
new Date('1977-12-14'),
Sequence::of([new Date('1977-12-14'), new Date('2014-07-17'), new Date('1979-12-29')])->min($comparator)
);
}

#[@test, @values('values')]
#[Test, Values('values')]
public function max($min, $max, $values) {
Assert::equals($max, Sequence::of($values)->max());
}

#[@test, @values('comparators')]
#[Test, Values('comparators')]
public function max_using($comparator) {
Assert::equals(
new Date('2014-07-17'),
Expand Down
54 changes: 27 additions & 27 deletions src/test/php/util/data/unittest/CollectorsTest.class.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php namespace util\data\unittest;

use lang\XPClass;
use unittest\Assert;
use unittest\{Assert, Before, Test, Values};
use util\collections\{HashSet, HashTable, Vector};
use util\data\{Collector, Collectors, Sequence};

Expand All @@ -11,7 +11,7 @@ class CollectorsTest {
/**
* Sets up test, initializing people member
*/
#[@before]
#[Before]
public function setUp() {
$this->people= [
1549 => new Employee(1549, 'Timm', 'B', 15),
Expand Down Expand Up @@ -68,7 +68,7 @@ private function dinosaurEmployees() {
];
}

#[@test, @values('employeesName')]
#[Test, Values('employeesName')]
public function toList($nameOf) {
Assert::equals(['Timm', 'Alex', 'Dude'], Sequence::of($this->people)
->map($nameOf)
Expand All @@ -77,15 +77,15 @@ public function toList($nameOf) {
);
}

#[@test, @values('employeesName')]
#[Test, Values('employeesName')]
public function toList_with_extraction($nameOf) {
Assert::equals(['Timm', 'Alex', 'Dude'], Sequence::of($this->people)
->collect(Collectors::toList($nameOf))
->elements()
);
}

#[@test, @values('employeesName')]
#[Test, Values('employeesName')]
public function toSet($nameOf) {
Assert::equals(['Timm', 'Alex', 'Dude'], Sequence::of($this->people)
->map($nameOf)
Expand All @@ -94,15 +94,15 @@ public function toSet($nameOf) {
);
}

#[@test, @values('employeesName')]
#[Test, Values('employeesName')]
public function toSet_with_extraction($nameOf) {
Assert::equals(['Timm', 'Alex', 'Dude'], Sequence::of($this->people)
->collect(Collectors::toSet($nameOf))
->toArray()
);
}

#[@test, @values('employeesName')]
#[Test, Values('employeesName')]
public function toCollection_with_HashSet_class($nameOf) {
Assert::equals(['Timm', 'Alex', 'Dude'], Sequence::of($this->people)
->map($nameOf)
Expand All @@ -111,7 +111,7 @@ public function toCollection_with_HashSet_class($nameOf) {
);
}

#[@test, @values('employeesName')]
#[Test, Values('employeesName')]
public function toMap($nameOf) {
$map= new HashTable();
$map[1549]= 'Timm';
Expand All @@ -124,7 +124,7 @@ function($e) { return $e->id(); },
)));
}

#[@test, @values('employeesName')]
#[Test, Values('employeesName')]
public function toMap_uses_complete_value_if_value_function_omitted($nameOf) {
$map= new HashTable();
$map['Timm']= $this->people[1549];
Expand All @@ -137,15 +137,15 @@ public function toMap_uses_complete_value_if_value_function_omitted($nameOf) {
)));
}

#[@test]
#[Test]
public function toMap_can_use_sequence_keys() {
$map= new HashTable();
$map['color']= 'green';

Assert::equals($map, Sequence::of(['color' => 'green'])->collect(Collectors::toMap()));
}

#[@test]
#[Test]
public function toMap_key_function_can_be_omitted() {
$map= new HashTable();
$map['color']= 'GREEN';
Expand All @@ -156,7 +156,7 @@ public function toMap_key_function_can_be_omitted() {
)));
}

#[@test]
#[Test]
public function collect_with_key() {
$result= Sequence::of(['color' => 'green', 'price' => 12.99])->collect(new Collector(
function() { return []; },
Expand All @@ -165,83 +165,83 @@ function(&$result, $arg, $key) { $result[strtoupper($key)]= $arg; }
Assert::equals(['COLOR' => 'green', 'PRICE' => 12.99], $result);
}

#[@test, @values('employeesYears')]
#[Test, Values('employeesYears')]
public function summing_years($yearsOf) {
Assert::equals(33, Sequence::of($this->people)
->collect(Collectors::summing($yearsOf))
);
}

#[@test, @values('employeesYears')]
#[Test, Values('employeesYears')]
public function summing_elements($yearsOf) {
Assert::equals(33, Sequence::of($this->people)
->map($yearsOf)
->collect(Collectors::summing())
);
}

#[@test, @values('employeesYears')]
#[Test, Values('employeesYears')]
public function averaging_years($yearsOf) {
Assert::equals(11, Sequence::of($this->people)
->collect(Collectors::averaging($yearsOf))
);
}

#[@test, @values('employeesYears')]
#[Test, Values('employeesYears')]
public function averaging_elements($yearsOf) {
Assert::equals(11, Sequence::of($this->people)
->map($yearsOf)
->collect(Collectors::averaging())
);
}

#[@test]
#[Test]
public function counting() {
Assert::equals(3, Sequence::of($this->people)
->collect(Collectors::counting())
);
}

#[@test, @values('employeesDepartment')]
#[Test, Values('employeesDepartment')]
public function mapping_by_department($departmentOf) {
Assert::equals(new Vector(['B', 'I', 'I']), Sequence::of($this->people)
->collect(Collectors::mapping($departmentOf))
);
}

#[@test]
#[Test]
public function joining_names() {
Assert::equals('Timm, Alex, Dude', Sequence::of($this->people)
->map(function($e) { return $e->name(); })
->collect(Collectors::joining())
);
}

#[@test]
#[Test]
public function joining_names_with_semicolon() {
Assert::equals('Timm;Alex;Dude', Sequence::of($this->people)
->map(function($e) { return $e->name(); })
->collect(Collectors::joining(';'))
);
}

#[@test]
#[Test]
public function joining_names_with_prefix_and_suffix() {
Assert::equals('(Timm, Alex, Dude)', Sequence::of($this->people)
->map(function($e) { return $e->name(); })
->collect(Collectors::joining(', ', '(', ')'))
);
}

#[@test, @values('employeesDepartment')]
#[Test, Values('employeesDepartment')]
public function groupingBy($departmentOf) {
$this->assertHashTable(
['B' => new Vector([$this->people[1549]]), 'I' => new Vector([$this->people[1552], $this->people[6100]])],
Sequence::of($this->people)->collect(Collectors::groupingBy($departmentOf))
);
}

#[@test]
#[Test]
public function groupingBy_with_summing_of_years() {
$this->assertHashTable(['B' => 15, 'I' => 18], Sequence::of($this->people)
->collect(Collectors::groupingBy(
Expand All @@ -251,7 +251,7 @@ function($e) { return $e->department(); },
);
}

#[@test]
#[Test]
public function groupingBy_with_averaging_of_years() {
$this->assertHashTable(['B' => 15, 'I' => 9], Sequence::of($this->people)
->collect(Collectors::groupingBy(
Expand All @@ -261,15 +261,15 @@ function($e) { return $e->department(); },
);
}

#[@test, @values('dinosaurEmployees')]
#[Test, Values('dinosaurEmployees')]
public function partitioningBy($moreThanTen) {
$this->assertHashTable(
[true => new Vector([$this->people[1549], $this->people[1552]]), false => new Vector([$this->people[6100]])],
Sequence::of($this->people)->collect(Collectors::partitioningBy($moreThanTen))
);
}

#[@test]
#[Test]
public function partitioningBy_handles_non_booleans() {
$this->assertHashTable(
[true => new Vector(['Test', 'Unittest']), false => new Vector(['Trial & Error'])],
Expand All @@ -279,7 +279,7 @@ public function partitioningBy_handles_non_booleans() {
);
}

#[@test]
#[Test]
public function collecting_with_key() {
Sequence::of($this->people)
->collecting($result, new Collector(
Expand Down
8 changes: 4 additions & 4 deletions src/test/php/util/data/unittest/ContinuationOfTest.class.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php namespace util\data\unittest;

use unittest\Assert;
use unittest\{Assert, Test, Values};
use util\data\{ContinuationOf, Sequence};

class ContinuationOfTest {

#[@test, @values('util.data.unittest.Enumerables::validArrays')]
#[Test, Values('util.data.unittest.Enumerables::validArrays')]
public function at_beginning($input) {
$it= Sequence::of($input)->getIterator();
$it->rewind();

Assert::equals([0 => 1, 1 => 2, 2 => 3], iterator_to_array(new ContinuationOf($it)));
}

#[@test, @values('util.data.unittest.Enumerables::validArrays')]
#[Test, Values('util.data.unittest.Enumerables::validArrays')]
public function after_first($input) {
$it= Sequence::of($input)->getIterator();
$it->rewind();
Expand All @@ -22,7 +22,7 @@ public function after_first($input) {
Assert::equals([1 => 2, 2 => 3], iterator_to_array(new ContinuationOf($it)));
}

#[@test, @values('util.data.unittest.Enumerables::validArrays')]
#[Test, Values('util.data.unittest.Enumerables::validArrays')]
public function at_end($input) {
$it= Sequence::of($input)->getIterator();
$it->rewind();
Expand Down
Loading