Skip to content

Commit

Permalink
添加单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
he426100 authored Dec 25, 2023
1 parent c51ca27 commit cf0ca36
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/phpunit/CollectionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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);
}

public function testCounter()
{
$Counter = PyCore::import('collections')->Counter;

$words = ['red', 'blue', 'red', 'green', 'blue', 'blue'];
$word_counts = $Counter($words);
$this->assertEquals(PyCore::dict($word_counts), PyCore::dict(['blue' => 3, 'red' => 2, 'green' => 1]));
}
}

0 comments on commit cf0ca36

Please sign in to comment.