Skip to content

Commit

Permalink
update doc, add dict iter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Dec 25, 2023
1 parent c591b1d commit 99fb7eb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/cn/python/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cmake . -D PHP_CONFIG=/usr/local/bin/python3-config
make -j 4
```

编译成功后在 `tests/lib` 目录下会生成 `phpy.so`,可以将此文件复制到任意 `Python``sys.path` 目录中。
编译成功后在 `lib` 目录下会生成 `phpy.so`,可以将此文件复制到任意 `Python``sys.path` 目录中。

## conda 工具

Expand Down
38 changes: 38 additions & 0 deletions tests/phpunit/DictTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,42 @@ public function testDict()

$this->assertEquals(10, $dict->count());
}

public function testIter()
{
$map = [];
$dict = new PyDict();
$n = 10;
while ($n--) {
$key = 'key-' . $n;
$value = uniqid();
$map[$key] = $value;
$dict[$key] = $value;
}
$keys = [];
foreach ($dict as $k => $v) {
$keys[] = $k;
$this->assertEquals($v, $map[$k]);
}
$this->assertEquals($keys, array_keys($map));
}

public function testIterInt()
{
$map = [];
$dict = new PyDict();
$n = 10;
while ($n--) {
$key = random_int(1, 1 << 31);
$value = uniqid();
$map[$key] = $value;
$dict[$key] = $value;
}
$keys = [];
foreach ($dict as $k => $v) {
$keys[] = $k;
$this->assertEquals($v, $map[$k]);
}
$this->assertEquals($keys, array_keys($map));
}
}

0 comments on commit 99fb7eb

Please sign in to comment.