Skip to content

Added TC for testing if palindrome#169

Open
laynotlee wants to merge 6 commits intoutgheith:mainfrom
laynotlee:leolei/palindromes
Open

Added TC for testing if palindrome#169
laynotlee wants to merge 6 commits intoutgheith:mainfrom
laynotlee:leolei/palindromes

Conversation

@laynotlee
Copy link

Two functions: first case is if palindrome length is less than or equal to 1.
Second case is use recursion to see if the middle string is also palindrome.

@laynotlee
Copy link
Author

Modified my test case according to suggestions, made a function a predicate to be more idiomatic.

Copy link
Collaborator

@ChristopherThomasHill ChristopherThomasHill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look good to me. I think this is a good simplistic inductive test case for people to think about.

// Test 2:
// If a is a palindrome of length > 1, then its "middle"
// (drop first and last element) is also a palindrome.
method {induction: false} Test_Palindrome_Middle(a: seq<int>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo – should be {:induction false} instead of {induction: false}

// A sequence is a palindrome if:
// - length 0 or 1: true
// - otherwise: first == last AND the middle part is a palindrome.
predicate {:induction false} IsPalindrome(a: seq<int>): bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

predicates always return a bool; dafny errors because of the explicit declaration

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch, I saw the predicate but didn't check the explicit declaration at the end, oops.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know that would be an error, just fixed.

@amrina18
Copy link
Contributor

amrina18 commented Dec 4, 2025

This verifies with the lemma bodies empty...

@laynotlee
Copy link
Author

This verifies with the lemma bodies empty...

Okay, should be fixed now.

Copy link
Collaborator

@JohnEdwardJennings JohnEdwardJennings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get

testcases/palindrome.dfy(8,29): Error: invalid UnaryExpression
  |
8 | predicate {:induction false, :opaque} IsPalindrome(a: seq<int>)
  |                              ^

testcases/palindrome.dfy(8,36): Error: invalid TopDecl
  |
8 | predicate {:induction false, :opaque} IsPalindrome(a: seq<int>)
  |                                     ^

when running the revised version locally on my machine.

@laynotlee
Copy link
Author

I get

testcases/palindrome.dfy(8,29): Error: invalid UnaryExpression
  |
8 | predicate {:induction false, :opaque} IsPalindrome(a: seq<int>)
  |                              ^

testcases/palindrome.dfy(8,36): Error: invalid TopDecl
  |
8 | predicate {:induction false, :opaque} IsPalindrome(a: seq<int>)
  |                                     ^

when running the revised version locally on my machine.

Okay, should have workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants