Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: b36fe569ca
Fetching contributors…

Cannot retrieve contributors at this time

145 lines (134 sloc) 3.9 kb
#! /usr/bin/env racket
#lang racket
(require rackunit "2-problem-solving.rkt")
(define (result-tests)
(test-case
"result test"
(check-equal? (result (state 'neamt)
(action (state 'neamt)
(state 'iasi)))
(state 'iasi))
(check-equal? (result (state 'hirsova)
(action (state 'hirsova)
(state 'eforie)))
(state 'eforie))
(check-exn
exn:fail?
(lambda ()
(result (state 'neamt)
(action (state (state 'neamt)
(state 'eforie))))))))
(define (step-cost-tests)
(test-case
"step-cost tests"
(check-equal? (step-cost (state 'lugoj)
(action (state 'lugoj)
(state 'mehadia)))
70)
(check-equal? (step-cost (state 'neamt)
(action (state 'neamt)
(state 'iasi)))
87)
(check-exn
exn:fail?
(lambda ()
(step-cost (state 'neamt)
(action (state 'iasi)
(state 'neamt)))))))
(define (goal-test-tests)
(test-case
"goal-test tests"
(check-true (goal-test (state 'bucharest)))
(check-false (goal-test (state 'neamt)))))
(define (path-cost-tests)
(test-case
"path-cost tests"
(check-equal? (path-cost '())
0
"empty path should cost 0")
(check-equal?
(path-cost
(list (list
(state 'arad)
(action (state 'arad)
(state 'zerind))
(state 'zerind))))
75
"path from ((arad -> zerin)) should cost 75")
(check-equal?
(path-cost
(list (list
(state 'arad)
(action (state 'arad)
(state 'zerind))
(state 'zerind))
(list
(state 'zerind)
(action (state 'zerind)
(state 'arad))
(state 'arad))))
150
"path ((arad -> zerind) (zerind -> arad)) should cost 150")))
(define (path-valid?-tests)
(test-case
"path-valid? tests"
(check-true
(path-valid?
(list (list
(state 'arad)
(action (state 'arad)
(state 'zerind))
(state 'zerind))))
"path from ((arad -> zerin)) should be valid")
(check-true
(path-valid?
(list (list
(state 'arad)
(action (state 'arad)
(state 'zerind))
(state 'zerind))
(list
(state 'zerind)
(action (state 'zerind)
(state 'arad))
(state 'arad))))
"path ((arad -> zerind) (zerind -> arad)) should be valid")
(check-false
(path-valid?
(list (list
(state 'arad)
(action (state 'arad)
(state 'oradea))
(state 'oradea))))
"path ((arad -> oradea)) should be invalid")
(check-false
(path-valid?
(list (list
(state 'arad)
(action (state 'arad)
(state 'zerind))
(state 'oradea))))
"path ((arad -> zerind)) should be not end in oradea")
(check-false
(path-valid?
(list (list
(state 'arad)
(action (state 'arad)
(state 'zerind))
(state 'zerind))
(list
(state 'arad)
(action (state 'arad)
(state 'zerind))
(state 'zerind))))
"path ((arad -> zerind) (arad -> zerind)) should be invalid")))
(define all-tests
(test-suite
"2-problem-solving.rkt tests"
(step-cost-tests)
(result-tests)
(goal-test-tests)
(path-valid?-tests)
(path-cost-tests)))
(require rackunit/text-ui)
(run-tests all-tests)
Jump to Line
Something went wrong with that request. Please try again.