Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 34s
lib/maude/searchpath.sx — mau/search-path returns the shortest sequence of states from start to goal (the solution moves), mau/search-length its step count. BFS over all one-step successors, threading the path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
67 lines
1.7 KiB
Plaintext
67 lines
1.7 KiB
Plaintext
;; lib/maude/tests/searchpath.sx — search returning the witness path.
|
|
|
|
(define msp-pass 0)
|
|
(define msp-fail 0)
|
|
(define msp-failures (list))
|
|
|
|
(define
|
|
msp-check!
|
|
(fn
|
|
(name got expected)
|
|
(if
|
|
(= got expected)
|
|
(set! msp-pass (+ msp-pass 1))
|
|
(do
|
|
(set! msp-fail (+ msp-fail 1))
|
|
(append!
|
|
msp-failures
|
|
(str name " expected: " expected " got: " got))))))
|
|
|
|
(define
|
|
msp-ndet
|
|
(mau/parse-module
|
|
"mod NDET is\n sort S .\n ops a b c d goal : -> S .\n rl [r1] : a => b .\n rl [r2] : a => c .\n rl [r3] : b => d .\n rl [r4] : c => goal .\nendm"))
|
|
|
|
;; shortest path a -> c -> goal
|
|
(msp-check!
|
|
"path-to-goal"
|
|
(mau/search-path msp-ndet "a" "goal" 5)
|
|
(list "a" "c" "goal"))
|
|
(msp-check!
|
|
"path-length"
|
|
(mau/search-length msp-ndet "a" "goal" 5)
|
|
2)
|
|
(msp-check!
|
|
"path-self"
|
|
(mau/search-path msp-ndet "a" "a" 3)
|
|
(list "a"))
|
|
(msp-check!
|
|
"path-one-step"
|
|
(mau/search-path msp-ndet "a" "b" 3)
|
|
(list "a" "b"))
|
|
(msp-check!
|
|
"path-unreachable"
|
|
(mau/search-path msp-ndet "d" "goal" 5)
|
|
nil)
|
|
(msp-check!
|
|
"path-depth-limited"
|
|
(mau/search-path msp-ndet "a" "goal" 1)
|
|
nil)
|
|
|
|
;; a counter that ticks up: path shows each state
|
|
(define
|
|
msp-walk
|
|
(mau/parse-module
|
|
"mod WALK is\n sort Pos .\n op z : -> Pos .\n op s : Pos -> Pos .\n op p : Pos -> Pos .\n var X : Pos .\n rl [step] : p(X) => p(s(X)) .\nendm"))
|
|
|
|
(msp-check!
|
|
"walk-path"
|
|
(mau/search-path msp-walk "p(z)" "p(s(s(z)))" 5)
|
|
(list "p(z)" "p(s(z))" "p(s(s(z)))"))
|
|
(msp-check!
|
|
"walk-length"
|
|
(mau/search-length msp-walk "p(z)" "p(s(s(s(z))))" 6)
|
|
3)
|
|
|
|
(define mau-searchpath-tests-run! (fn () {:failures msp-failures :total (+ msp-pass msp-fail) :passed msp-pass :failed msp-fail}))
|