flatrr/tests/FlatArrayPushPopTest.php

34 lines
985 B
PHP
Raw Normal View History

2018-08-17 21:02:50 +00:00
<?php
2018-08-17 22:09:45 +00:00
/* Flatrr | https://gitlab.com/byjoby/flatrr | MIT License */
2018-08-17 21:02:50 +00:00
declare(strict_types=1);
2018-08-17 22:09:45 +00:00
namespace Flatrr;
2018-08-17 21:02:50 +00:00
use PHPUnit\Framework\TestCase;
class FlatArrayPushPopTest extends TestCase
{
public function testPushPop()
{
$f = new FlatArray();
$f->push(null, 'foo');
$f->push(null, 'bar');
$this->assertEquals(['foo','bar'], $f->get());
$this->assertEquals('bar', $f->pop(null));
$this->assertEquals(['foo'], $f->get());
$this->assertEquals('foo', $f->pop(null));
$this->assertEquals([], $f->get());
}
public function testShiftUnshift()
{
$f = new FlatArray();
2018-08-30 22:18:42 +00:00
$f->unshift(null, 'foo');
$f->unshift(null, 'bar');
2018-08-17 21:02:50 +00:00
$this->assertEquals(['bar','foo'], $f->get());
2018-08-30 22:18:42 +00:00
$this->assertEquals('bar', $f->shift(null));
2018-08-17 21:02:50 +00:00
$this->assertEquals(['foo'], $f->get());
2018-08-30 22:18:42 +00:00
$this->assertEquals('foo', $f->shift(null));
2018-08-17 21:02:50 +00:00
$this->assertEquals([], $f->get());
}
}