Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testcase Syntax #19

Open
TeamSPoon opened this issue Nov 14, 2023 · 6 comments
Open

Testcase Syntax #19

TeamSPoon opened this issue Nov 14, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@TeamSPoon
Copy link
Collaborator

Going to suggest for testcases (since this works in Rust MeTTa) we adopt a standard test writing format

; it is non-deterministic: each value is matched against all cases
!(assertEqual
 (case (+ 1 (superpose (1 2 3)))
  ((3 OK-3)
   (4 OK-4)))
 (superpose (OK-3 OK-4)))
; one case can produce multiple results
!(assertEqual
  (case (+ 1 (superpose (1 2 3)))
     (($x (+ 1 $x))))
  (superpose (3 4 5)))
@TeamSPoon TeamSPoon added the enhancement New feature or request label Nov 14, 2023
@TeamSPoon
Copy link
Collaborator Author

Most tests seem to be described with the addition of these two functions

assertEqualToResult
assertEqual

(isa red color)
(isa green color)
(isa blue color)
!(assertEqualToResult
  (match &self (isa $color color) $color)
  (red green blue))

@patham9
Copy link
Collaborator

patham9 commented Nov 14, 2023

The tests in MeTTamorph directly run both MeTTa interpreter and MeTTamorph on the same test files each and check whether the output matches, this is the reason why such assertions are unnecessary. Producing the same output is the implicit assertion which is reported when it fails.

@Necr0x0Der
Copy link
Contributor

Yes, I agree that comparing results from compiled and not compiled versions is a good approach for this project, but it may turn out to be the case that something in addition is needed. Some MeTTa code cannot be supported by the compiler and running compiled functions from such the code should also be checked. Thus, I suppose that more tests will be added, which will not be completely compiled. It will still be possible to compare partly-compiled and not compiled versions, but writing such tests may appear not too convenient. Let's try and see how it goes.

@TeamSPoon
Copy link
Collaborator Author

TeamSPoon commented Nov 14, 2023

Why i was suggesting it is that most all tests in hyperon-experimental https://github.com/trueagi-io/hyperon-experimental/tree/main/python/tests/scripts use assertEqualToResult assertEqual and didn't see wanting to have to edit/break those tests files for metta-morph :)

@Necr0x0Der
Copy link
Contributor

If we'd like to run all the unit tests from the main repo with the use of compilation by metta-morph, this would make perfect sense. Well, it also makes sense to be able to run these tests manually to check the results under metta-morph. Thus, I agree that it makes sense to introduce asserts for this sake, although it doesn't imply that unit tests in metta-morph itself should necessarily use them.

@patham9
Copy link
Collaborator

patham9 commented Nov 14, 2023

Good point, we can add these assert functions at least.

A portable version (TODO):

(= (assertEqual $x $y) (If (not (== $x $y)) FAIL))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants