Closed TeamSPoon closed 1 week ago
adding a handfull of other tests...
;; Test unique with variables
;; This test checks that unique handles variables correctly, ensuring that each unique instance is preserved.
!(assertEqual
(unique (superpose ($x $y $x $z)))
(superpose ($x $y $z))
)
;; Test unique with variables in nested lists
;; This test checks that unique correctly handles variables within nested lists, preserving each unique nested structure.
!(assertEqual
(unique (superpose ((:: $x $y) (:: $x $z) (:: $x $y) (:: $a $b))))
(superpose ((:: $x $y) (:: $x $z) (:: $a $b)))
)
;; Test unique with repeated variables in nested lists
;; This test ensures that unique treats identical nested lists with variables as duplicates, reducing them to a single instance.
!(assertEqual
(unique (superpose ((:: $x $y) (:: $x $y) (:: $x $z) (:: $x $y))))
(superpose ((:: $x $y) (:: $x $z)))
)
;; Test unique with mixed types and variables in nested lists
;; This test checks that unique handles a mix of nested structures with variables, symbols, and other data types correctly.
!(assertEqual
(unique (superpose ((:: 1 $x) (:: $x "hello") (:: 1 $x) (:: $y $z) (:: $x "hello"))))
(superpose ((:: 1 $x) (:: $x "hello") (:: $y $z)))
)
;; Test unique with complex nested structures including variables
;; This test verifies that unique handles more complex nested structures containing variables, preserving each unique structure.
!(assertEqual
(unique (superpose ((:: $x (:: a b)) (:: $x (:: a b)) (:: (:: 1 $x) (:: 2 $y)) (:: (:: 1 $x) (:: 2 $y)))))
(superpose ((:: $x (:: a b)) (:: (:: 1 $x) (:: 2 $y))))
)
Implement the
unique
Function and Add Test CasesThis issue involves implementing the
unique
function in MeTTa, which should take non-deterministic results and return non-deterministic results with duplicates removed. The goal is to handle lists of various types, including numbers, symbols, nested structures, and mixed types, while ensuring correct behavior in all scenarios.Task Description
Implement the
unique
Function:unique
function should accept non-deterministic input, process it to remove duplicates, and return a non-deterministic output. The function must preserve the order of the first occurrence of each unique element.Example behavior:
Create the Test File:
unique_test.metta
should be added to thetests/baseline_compat/hyperon-mettalog_sanity
directory.Define and Test the
list-to-set
Function:Add the following function definition:
Include the Following Test Cases:
Run and Verify:
Expected Outcome
The
unique
function should correctly handle non-deterministic input, returning non-deterministic results with duplicates removed. The function should work correctly with lists of varying types, including duplicates, single elements, nested lists, and mixed types. Thelist-to-set
function should be tested to confirm that it correctly collapses duplicates into a unique set. The tests should confirm that the functions behave as expected across these scenarios, ensuring consistency with MeTTa's non-deterministic evaluation principles.