Working through extra credit for ch20 ex19

cat-town
Dan Buch 13 years ago
parent 874eb4f3a2
commit 341d626870

1
.gitignore vendored

@ -6,3 +6,4 @@
!*.py
!*.h
!*.mk
!test_*.sh

@ -7,9 +7,13 @@ all: $(EXERCISES)
$(MAKE) -f ex19.mk
test: all
$(MAKE) -f ex19.mk test
clean:
rm -f $(EXERCISES)
$(MAKE) -f ex19.mk clean
.PHONY: all clean
.PHONY: all test clean

@ -46,7 +46,6 @@ Object MonsterProto = {
void *Room_move(void *self, Direction direction)
{
assert(self != NULL);
assert(direction);
Room *room = self;
Room *next = NULL;
@ -70,6 +69,8 @@ void *Room_move(void *self, Direction direction)
if(next) {
next->_(describe)(next);
} else {
printf("mumble mumble.\n");
}
return next;
@ -103,7 +104,6 @@ Object RoomProto = {
void *Map_move(void *self, Direction direction)
{
assert(self != NULL);
assert(direction);
Map *map = self;
Room *location = map->location;
@ -113,6 +113,8 @@ void *Map_move(void *self, Direction direction)
if(next) {
map->location = next;
} else {
map->location = location;
}
return next;
@ -176,9 +178,6 @@ int process_input(Map *game)
printf("\n> ");
char ch = getchar();
assert(ch != EOF);
getchar(); // eat ENTER
int damage = rand() % 4;
switch(ch) {
@ -219,6 +218,7 @@ int process_input(Map *game)
printf("What?: %d\n", ch);
}
getchar(); // eat ENTER
return 1;
}

@ -2,8 +2,16 @@ CFLAGS=-Wall -g
all: ex19
ex19: object.o
test:
./test_ex19.sh
clean:
rm -f ex19
rm -f object.o
rm -f ex19 object.o
.PHONY: all test clean

@ -85,6 +85,7 @@ void *Object_new(size_t size, Object proto, char *description)
return NULL;
} else {
// all done, we made an object of any type
assert(el != NULL);
return el;
}
}

@ -0,0 +1,77 @@
#!/bin/bash
EXIT_CODE=0
run_test()
{
echo -n " $1"
cat $2 | ./ex19 >/dev/null
if [[ $? -eq 0 ]]
then
echo " ... OK"
else
echo " ... FAIL"
EXIT_CODE=1
fi
rm -f $2
}
tmp_01=`mktemp`
cat > $tmp_01 <<EOF
l
n
w
n
w
n
w
e
w
e
e
e
s
s
w
w
n
a
a
a
a
a
a
a
a
a
a
a
a
EOF
tmp_02=`mktemp`
cat > $tmp_02 <<EOF
l
a
a
a
a
a
n
hutesoahutesohas
999999999999
l
n
n
n
e
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
EOF
run_test '01' $tmp_01
run_test '02' $tmp_02
exit $EXIT_CODE
Loading…
Cancel
Save