mirror of
https://github.com/php-win-ext/phpy.git
synced 2026-03-24 17:02:15 +01:00
* 修正只有kwargs没有args时报错
* 添加单元测试
* fix
* update
* Update core.cc
---------
Co-authored-by: 弄月 <{ID}+{username}@users.noreply.github.com>
Co-authored-by: Tianfeng.Han <rango@swoole.com>
29 lines
960 B
PHP
29 lines
960 B
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class CollectionsTest extends TestCase
|
|
{
|
|
public function testNamedTuple()
|
|
{
|
|
$namedtuple = PyCore::import('collections')->namedtuple;
|
|
$Person = $namedtuple('Person', ['name', 'age', 'gender']);
|
|
$p1 = $Person(name: '阮奇桢', age: 40, gender: '男');
|
|
$this->assertEquals('阮奇桢', $p1->name);
|
|
$this->assertEquals(40, $p1->age);
|
|
$this->assertEquals('男', $p1->gender);
|
|
|
|
[$name, $age, $gender] = $p1;
|
|
$this->assertEquals(['阮奇桢', 40, '男'], [(string)$name, (int)$age, (string)$gender]);
|
|
}
|
|
|
|
public function testCounter()
|
|
{
|
|
$Counter = PyCore::import('collections')->Counter;
|
|
|
|
$words = ['red', 'blue', 'red', 'green', 'blue', 'blue'];
|
|
$word_counts = $Counter($words);
|
|
$this->assertEquals(['blue' => 3, 'red' => 2, 'green' => 1], [...PyCore::dict($word_counts)]);
|
|
}
|
|
}
|