106 lines
2.7 KiB
PHP
106 lines
2.7 KiB
PHP
<?php
|
|
|
|
// require_once(DIR_ALVEOLATA . '/definitions.php');
|
|
require_once(DIR_ALVEOLATA . '/term/substitution.php');
|
|
|
|
|
|
\alveolata\test\add(
|
|
[
|
|
'name' => 'alveolata',
|
|
'sections' => [
|
|
[
|
|
'name' => 'term',
|
|
'setup' => function (&$environment) {
|
|
// foo(x,y)
|
|
$environment['x'] = new \alveolata\term\class_function(
|
|
'foo',
|
|
[
|
|
new \alveolata\term\class_variable('x'),
|
|
new \alveolata\term\class_variable('y'),
|
|
]
|
|
);
|
|
// foo(bar(),z)
|
|
$environment['y'] = new \alveolata\term\class_function(
|
|
'foo',
|
|
[
|
|
new \alveolata\term\class_function('bar', []),
|
|
// new \alveolata\term\class_function('baz', []),
|
|
new \alveolata\term\class_variable('z'),
|
|
]
|
|
);
|
|
},
|
|
'sections' => [
|
|
[
|
|
'name' => 'substitution-instance',
|
|
'cases' => [
|
|
[
|
|
'name' => 'test',
|
|
'procedure' => function ($assert, &$environment) {
|
|
$substitution = new \alveolata\term\struct_substitution(
|
|
[
|
|
'x' => new \alveolata\term\class_function('qux', []),
|
|
]
|
|
);
|
|
$x_actual = \alveolata\term\substitution_instance($substitution, $environment['x']);
|
|
$x_expected = new \alveolata\term\class_function(
|
|
'foo',
|
|
[
|
|
new \alveolata\term\class_function('qux', []),
|
|
new \alveolata\term\class_variable('y'),
|
|
]
|
|
);
|
|
$assert->is(\alveolata\term\equal($x_expected, $x_actual));
|
|
},
|
|
],
|
|
],
|
|
],
|
|
[
|
|
'name' => 'unifiers',
|
|
'cases' => [
|
|
[
|
|
'name' => 'test',
|
|
'procedure' => function ($assert, &$environment) {
|
|
$substitutions = \alveolata\term\unifiers(
|
|
[
|
|
[
|
|
'first' => $environment['x'],
|
|
'second' => $environment['y'],
|
|
]
|
|
]
|
|
);
|
|
$assert->equal(count($substitutions), 2);
|
|
foreach ($substitutions as $substitution) {
|
|
$assert->equal(count($substitution->mapping), 2);
|
|
$assert->is(
|
|
\alveolata\term\equal(
|
|
$substitution->mapping['x'],
|
|
new \alveolata\term\class_function('bar', []),
|
|
)
|
|
);
|
|
if (array_key_exists('y', $substitution->mapping)) {
|
|
$assert->is(
|
|
\alveolata\term\equal(
|
|
$substitution->mapping['y'],
|
|
new \alveolata\term\class_variable('z', []),
|
|
)
|
|
);
|
|
}
|
|
if (array_key_exists('z', $substitution->mapping)) {
|
|
$assert->is(
|
|
\alveolata\term\equal(
|
|
$substitution->mapping['z'],
|
|
new \alveolata\term\class_variable('y', []),
|
|
)
|
|
);
|
|
}
|
|
}
|
|
},
|
|
],
|
|
],
|
|
],
|
|
],
|
|
]
|
|
]
|
|
]
|
|
);
|
|
|