Skip to content

Added TC for testing if palindrome#169

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

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

Conversation

@laynotlee

Copy link
Copy Markdown

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.

Comment thread testcases/palindrome.dfy Outdated
Comment thread testcases/palindrome.dfy Outdated
Comment thread testcases/palindrome.dfy Outdated
@laynotlee

Copy link
Copy Markdown
Author

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

@ChristopherThomasHill ChristopherThomasHill left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread testcases/palindrome.dfy Outdated
// 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
Copy Markdown
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}

Comment thread testcases/palindrome.dfy Outdated
// 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

amrina18 commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

This verifies with the lemma bodies empty...

@laynotlee

Copy link
Copy Markdown
Author

This verifies with the lemma bodies empty...

Okay, should be fixed now.

@JohnEdwardJennings JohnEdwardJennings left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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