Merge branch 'master' of http://github.com/mpereira/tty-solitaire
This commit is contained in:
commit
080e4af432
@ -2,6 +2,14 @@
|
||||
|
||||
* CHANGELOG
|
||||
|
||||
** [[https://github.com/mpereira/tty-solitaire/releases/tag/v1.2.0][v1.2.0]] (2020-05-31)
|
||||
*** Bug fixes
|
||||
- Fixed off-by-one issue in ~game:shuffle_deck()~. [[https://github.com/mpereira/tty-solitaire/pull/35][(#35)]]
|
||||
- Fixed memory leaks in game and test code. [[https://github.com/mpereira/tty-solitaire/pull/35][(#35)]]
|
||||
- Fixed broken tests. [[https://github.com/mpereira/tty-solitaire/pull/35][(#35)]]
|
||||
- Fixed card drawing issue that came up due to changes in newer versions of
|
||||
Ncurses. ([[https://github.com/mpereira/tty-solitaire/pull/41][#41]])
|
||||
|
||||
** [[https://github.com/mpereira/tty-solitaire/releases/tag/v1.1.1][v1.1.1]] (2018-11-10)
|
||||
*** Improvements
|
||||
- Added LICENSE.
|
||||
|
17
Makefile
17
Makefile
@ -1,10 +1,11 @@
|
||||
VERSION = 1.1.1
|
||||
VERSION = 1.2.0
|
||||
|
||||
CC ?= gcc
|
||||
CFLAGS ?= -g
|
||||
CFLAGS += -W -Wall -pedantic -ansi -std=c99 -DVERSION=\"$(VERSION)\" -fcommon
|
||||
|
||||
# OS X installs ncurses with wide character support, but not as "libncurses".
|
||||
# The Ncurses library with wide character support is available as "lncurses"
|
||||
# under macOS.
|
||||
ifeq ($(shell uname -s),Darwin)
|
||||
LDFLAGS += -lncurses
|
||||
else
|
||||
@ -48,15 +49,15 @@ ttysolitaire: $(SRC_OBJECTS)
|
||||
$(CC) $(CFLAGS) $(SRC) -o $(EXECUTABLE) $(SRC_OBJECTS) $(LDFLAGS)
|
||||
|
||||
test: $(SRC_OBJECTS) $(TESTS_OBJECTS)
|
||||
@$(CC) $(CFLAGS) $(TESTS_SRC) -o $(TESTS_EXECUTABLE) $(TESTS_OBJECTS) $(SRC_OBJECTS) $(LDFLAGS)
|
||||
@./$(TESTS_EXECUTABLE)
|
||||
$(CC) $(CFLAGS) $(TESTS_SRC) -o $(TESTS_EXECUTABLE) $(TESTS_OBJECTS) $(SRC_OBJECTS) $(LDFLAGS)
|
||||
./$(TESTS_EXECUTABLE)
|
||||
|
||||
clean:
|
||||
@rm -rf $(SRC_DIR)/*.o $(TESTS_DIR)/*.o $(EXECUTABLE) $(TESTS_EXECUTABLE)
|
||||
rm -rf $(SRC_DIR)/*.o $(TESTS_DIR)/*.o $(EXECUTABLE) $(TESTS_EXECUTABLE)
|
||||
|
||||
install:
|
||||
@install -d $(DESTDIR)$(PREFIX)/bin
|
||||
@install -m755 $(EXECUTABLE) $(DESTDIR)$(PREFIX)/bin/$(EXECUTABLE)
|
||||
install -d $(DESTDIR)$(PREFIX)/bin
|
||||
install -m755 $(EXECUTABLE) $(DESTDIR)$(PREFIX)/bin/$(EXECUTABLE)
|
||||
|
||||
uninstall:
|
||||
@rm -f $(PREFIX)/bin/$(EXECUTABLE)
|
||||
rm -f $(PREFIX)/bin/$(EXECUTABLE)
|
||||
|
81
README
81
README
@ -12,53 +12,94 @@
|
||||
- Ncurses with wide-char/UTF-8 support
|
||||
|
||||
** Install
|
||||
*** Using package managers
|
||||
**** Arch Linux
|
||||
#+begin_src bash
|
||||
pacman -S tty-solitaire
|
||||
#+end_src
|
||||
|
||||
**** macOS
|
||||
#+begin_src bash
|
||||
brew install tty-solitaire
|
||||
#+end_src
|
||||
|
||||
**** Void Linux
|
||||
#+begin_src bash
|
||||
xbps-install -S tty-solitaire
|
||||
#+end_src
|
||||
|
||||
**** FreeBSD
|
||||
#+begin_src bash
|
||||
pkg install tty-solitaire
|
||||
#+end_src
|
||||
|
||||
**** Slackware
|
||||
[[https://www.slackbuilds.org/repository/14.2/games/tty-solitaire/][Via Slackbuilds]].
|
||||
|
||||
**** ALT Linux
|
||||
#+begin_src bash
|
||||
apt-get install tty-solitaire
|
||||
#+end_src
|
||||
|
||||
We still need help making tty-solitaire available on Ubuntu, Fedora, Gentoo,
|
||||
and more. Please give us a hand at [[https://github.com/mpereira/tty-solitaire/issues/29][issue #29]] if you think you can help.
|
||||
|
||||
*** From source
|
||||
**** Install Ncurses
|
||||
tty-solitaire depends on Ncurses. Some platforms provide it out of the box
|
||||
and some don't, so you might need to install it yourself.
|
||||
|
||||
***** Ubuntu
|
||||
#+BEGIN_SRC bash
|
||||
#+begin_src bash
|
||||
sudo apt-get install libncurses5-dev libncursesw5-dev
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
***** macOS
|
||||
macOS has Ncurses with wide character support out of the box, so *there's
|
||||
nothing you need to do*. If you want to use other Ncurses libraries (from
|
||||
nothing you need to do*.
|
||||
|
||||
*If* for some reason you want to use other Ncurses libraries (from
|
||||
Macports, Homebrew, etc.) you are able to do it by specifying =LDLAGS= in
|
||||
the make invocation. See [[https://github.com/mpereira/tty-solitaire/pull/8][this pull request]] for more information.
|
||||
|
||||
**** Install tty-solitaire
|
||||
#+BEGIN_SRC text
|
||||
$ wget -O tty-solitaire-v1.1.0.tar.gz https://github.com/mpereira/tty-solitaire/archive/v1.1.0.tar.gz
|
||||
$ tar xvf tty-solitaire-v1.1.0.tar.gz
|
||||
$ cd tty-solitaire-1.1.0
|
||||
$ make
|
||||
$ sudo make install
|
||||
#+END_SRC
|
||||
*** Via package managers
|
||||
Check out https://github.com/mpereira/tty-solitaire/issues/29.
|
||||
#+begin_src bash
|
||||
wget -O tty-solitaire-v1.2.0.tar.gz https://github.com/mpereira/tty-solitaire/archive/v1.2.0.tar.gz
|
||||
tar xvf tty-solitaire-v1.2.0.tar.gz
|
||||
cd tty-solitaire-1.2.0
|
||||
make
|
||||
sudo make install
|
||||
#+end_src
|
||||
|
||||
** Play
|
||||
Run in your favorite shell:
|
||||
#+BEGIN_SRC bash
|
||||
|
||||
#+begin_src bash
|
||||
ttysolitaire
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
** Usage
|
||||
#+BEGIN_SRC text
|
||||
#+begin_src text
|
||||
usage: ttysolitaire [-v|--version] [-h|--help] [-p|--passes=NUMBER]
|
||||
-v, --version Show version
|
||||
-h, --help Show this message
|
||||
-p, --passes Number of passes through the deck
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
** Development
|
||||
*** Get the code
|
||||
#+BEGIN_SRC bash
|
||||
#+begin_src bash
|
||||
git clone https://github.com/mpereira/tty-solitaire.git
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
*** Run the unit tests
|
||||
#+BEGIN_SRC bash
|
||||
#+begin_src bash
|
||||
make test
|
||||
#+END_SRC
|
||||
#+end_src
|
||||
|
||||
*** [[https://invisible-island.net/ncurses/man/ncurses.3x.html][Ncurses documentation]]
|
||||
|
||||
*** [[https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/][Ncurses programming HOWTO]]
|
||||
|
||||
** Author
|
||||
[[http://murilopereira.com][Murilo Pereira]]
|
||||
|
@ -153,8 +153,8 @@ static void shuffle_deck(struct deck *deck) {
|
||||
card[i] = stack_pop(&(deck->stock));
|
||||
}
|
||||
srand(time(NULL));
|
||||
for (int i = 0; i < NUMBER_OF_CARDS - 1; i++) {
|
||||
random = i + (rand() % (NUMBER_OF_CARDS) - i);
|
||||
for (int i = 0; i < NUMBER_OF_CARDS; i++) {
|
||||
random = rand() % (NUMBER_OF_CARDS);
|
||||
tmp = *card[i];
|
||||
*card[i] = (*card[random]);
|
||||
*card[random] = tmp;
|
||||
@ -162,6 +162,7 @@ static void shuffle_deck(struct deck *deck) {
|
||||
for (int i = 0; i < NUMBER_OF_CARDS; i++) {
|
||||
stack_push(&(deck->stock), card[i]);
|
||||
}
|
||||
free(card);
|
||||
}
|
||||
|
||||
static void deal_cards(struct deck *deck) {
|
||||
|
@ -69,6 +69,7 @@ int stack_length(struct stack *stack) {
|
||||
void stack_push(struct stack **stack, struct card *card) {
|
||||
if (card) {
|
||||
if (stack_empty(*stack)) {
|
||||
card_free((*stack)->card);
|
||||
(*stack)->card = card;
|
||||
} else {
|
||||
/* Allocating by hand because stack_malloc() would
|
||||
|
@ -25,6 +25,9 @@ void test_card_dup() {
|
||||
|
||||
assert(card_0 != card_1);
|
||||
assert(cards_equal(card_0, card_1));
|
||||
|
||||
card_free(card_0);
|
||||
card_free(card_1);
|
||||
}
|
||||
|
||||
void test_card_set() {
|
||||
|
@ -25,6 +25,9 @@ void test_frame_dup() {
|
||||
|
||||
assert(frame_0 != frame_1);
|
||||
assert(frames_equal(frame_0, frame_1));
|
||||
|
||||
frame_free(frame_0);
|
||||
frame_free(frame_1);
|
||||
}
|
||||
|
||||
void test_frame_set() {
|
||||
|
@ -119,7 +119,7 @@ void test_valid_move_from_waste_pile_to_foundation_stacks() {
|
||||
|
||||
stack_malloc(&waste_pile);
|
||||
stack_init(waste_pile);
|
||||
card_set(waste_pile->card, ACE, SPADES, EXPOSED, WASTE_PILE_BEGIN_Y, WASTE_PILE_BEGIN_X);
|
||||
card_set(waste_pile->card, TWO, SPADES, EXPOSED, WASTE_PILE_BEGIN_Y, WASTE_PILE_BEGIN_X);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
stack_malloc(&foundation_stacks[i]);
|
||||
stack_init(foundation_stacks[i]);
|
||||
@ -129,7 +129,6 @@ void test_valid_move_from_waste_pile_to_foundation_stacks() {
|
||||
card_set(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X);
|
||||
card_set(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// TODO: fix error here
|
||||
assert(valid_move(waste_pile, foundation_stacks[i]));
|
||||
}
|
||||
stack_free(waste_pile);
|
||||
@ -143,20 +142,19 @@ void test_valid_move_from_waste_pile_to_maneuvre_stacks() {
|
||||
|
||||
stack_malloc(&waste_pile);
|
||||
stack_init(waste_pile);
|
||||
card_set(waste_pile->card, ACE, SPADES, EXPOSED, WASTE_PILE_BEGIN_Y, WASTE_PILE_BEGIN_X);
|
||||
card_set(waste_pile->card, ACE, DIAMONDS, EXPOSED, WASTE_PILE_BEGIN_Y, WASTE_PILE_BEGIN_X);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
stack_malloc(&maneuvre_stacks[i]);
|
||||
stack_init(maneuvre_stacks[i]);
|
||||
}
|
||||
card_set(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
card_set(maneuvre_stacks[0]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, TWO, CLUBS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, TWO, CLUBS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, TWO, CLUBS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
// TODO: fix error here
|
||||
assert(valid_move(waste_pile, maneuvre_stacks[i]));
|
||||
}
|
||||
stack_free(waste_pile);
|
||||
@ -219,15 +217,14 @@ void test_valid_move_from_foundation_stack_to_foundation_stacks() {
|
||||
stack_init(foundation_stacks[i]);
|
||||
}
|
||||
card_set(foundation_stacks[0]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_0_BEGIN_X);
|
||||
card_set(foundation_stacks[1]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_1_BEGIN_X);
|
||||
card_set(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X);
|
||||
card_set(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X);
|
||||
card_set(foundation_stacks[1]->card, TWO, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_1_BEGIN_X);
|
||||
card_set(foundation_stacks[2]->card, THREE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X);
|
||||
card_set(foundation_stacks[3]->card, FOUR, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (i == j) {
|
||||
if (i != j + 1) {
|
||||
assert(!valid_move(foundation_stacks[i], foundation_stacks[j]));
|
||||
} else {
|
||||
// TODO: fix error here
|
||||
assert(valid_move(foundation_stacks[i], foundation_stacks[j]));
|
||||
}
|
||||
}
|
||||
@ -247,22 +244,21 @@ void test_valid_move_from_foundation_stack_to_maneuvre_stacks() {
|
||||
}
|
||||
card_set(foundation_stacks[0]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_0_BEGIN_X);
|
||||
card_set(foundation_stacks[1]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_1_BEGIN_X);
|
||||
card_set(foundation_stacks[2]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X);
|
||||
card_set(foundation_stacks[3]->card, ACE, SPADES, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X);
|
||||
card_set(foundation_stacks[2]->card, ACE, CLUBS, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_2_BEGIN_X);
|
||||
card_set(foundation_stacks[3]->card, ACE, CLUBS, EXPOSED, FOUNDATION_BEGIN_Y, FOUNDATION_3_BEGIN_X);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
stack_malloc(&maneuvre_stacks[i]);
|
||||
stack_init(maneuvre_stacks[i]);
|
||||
}
|
||||
card_set(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
card_set(maneuvre_stacks[0]->card, TWO, HEARTS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, TWO, HEARTS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, TWO, HEARTS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, TWO, HEARTS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, TWO, DIAMONDS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, TWO, DIAMONDS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, TWO, DIAMONDS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 7; j++) {
|
||||
// TODO: fix error here
|
||||
assert(valid_move(foundation_stacks[i], maneuvre_stacks[j]));
|
||||
}
|
||||
}
|
||||
@ -342,16 +338,15 @@ void test_valid_move_from_maneuvre_stack_to_foundation_stacks() {
|
||||
stack_malloc(&maneuvre_stacks[i]);
|
||||
stack_init(maneuvre_stacks[i]);
|
||||
}
|
||||
card_set(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
card_set(maneuvre_stacks[0]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, TWO, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
// TODO: fix error here
|
||||
assert(valid_move(maneuvre_stacks[i], foundation_stacks[j]));
|
||||
}
|
||||
}
|
||||
@ -371,18 +366,17 @@ void test_valid_move_from_maneuvre_stack_to_maneuvre_stacks() {
|
||||
stack_init(maneuvre_stacks[i]);
|
||||
}
|
||||
card_set(maneuvre_stacks[0]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_0_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, ACE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
card_set(maneuvre_stacks[1]->card, TWO, HEARTS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_1_BEGIN_X);
|
||||
card_set(maneuvre_stacks[2]->card, THREE, CLUBS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_2_BEGIN_X);
|
||||
card_set(maneuvre_stacks[3]->card, FOUR, DIAMONDS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_3_BEGIN_X);
|
||||
card_set(maneuvre_stacks[4]->card, FIVE, SPADES, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_4_BEGIN_X);
|
||||
card_set(maneuvre_stacks[5]->card, SIX, DIAMONDS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_5_BEGIN_X);
|
||||
card_set(maneuvre_stacks[6]->card, SEVEN, CLUBS, EXPOSED, MANEUVRE_BEGIN_Y, MANEUVRE_6_BEGIN_X);
|
||||
for (int i = 0; i < 7; i++) {
|
||||
for (int j = 0; j < 7; j++) {
|
||||
if (i == j) {
|
||||
if (i + 1 != j) {
|
||||
assert(!valid_move(maneuvre_stacks[i], maneuvre_stacks[j]));
|
||||
} else {
|
||||
// TODO: fix error here
|
||||
assert(valid_move(maneuvre_stacks[i], maneuvre_stacks[j]));
|
||||
}
|
||||
}
|
||||
@ -412,6 +406,8 @@ void test_move_card_from_stack_empty_stack_to_stack_empty_stack() {
|
||||
assert(destination == new_destination);
|
||||
assert(stacks_equal(destination, destination_duplicate));
|
||||
|
||||
stack_free(origin_duplicate);
|
||||
stack_free(destination_duplicate);
|
||||
stack_free(origin);
|
||||
stack_free(destination);
|
||||
}
|
||||
@ -442,6 +438,8 @@ void test_move_card_from_stack_empty_stack_to_non_stack_empty_stack() {
|
||||
assert(destination == new_destination);
|
||||
assert(stacks_equal(destination, destination_duplicate));
|
||||
|
||||
stack_free(origin_duplicate);
|
||||
stack_free(destination_duplicate);
|
||||
stack_free(origin);
|
||||
stack_free(destination);
|
||||
}
|
||||
|
@ -30,6 +30,9 @@ void test_stack_dup() {
|
||||
|
||||
assert(stack_0 != stack_1);
|
||||
assert(stacks_equal(stack_0, stack_1));
|
||||
|
||||
stack_free(stack_0);
|
||||
stack_free(stack_1);
|
||||
}
|
||||
|
||||
void test_stack_empty_on_stack_empty_stack() {
|
||||
@ -185,6 +188,7 @@ void test_stack_pop_on_stack_with_one_element() {
|
||||
assert(stack_popped_card == card);
|
||||
|
||||
stack_free(stack);
|
||||
card_free(stack_popped_card);
|
||||
}
|
||||
|
||||
void test_stack_pop_on_stack_with_more_than_one_element() {
|
||||
@ -207,6 +211,7 @@ void test_stack_pop_on_stack_with_more_than_one_element() {
|
||||
assert(stack_popped_card == card[2]);
|
||||
|
||||
stack_free(stack);
|
||||
card_free(stack_popped_card);
|
||||
}
|
||||
|
||||
void test_stack_reverse_on_stack_empty_stack() {
|
||||
@ -220,6 +225,7 @@ void test_stack_reverse_on_stack_empty_stack() {
|
||||
assert(stacks_equal(stack_reversed_stack, old_stack));
|
||||
|
||||
stack_free(stack);
|
||||
stack_free(stack_reversed_stack);
|
||||
}
|
||||
|
||||
void test_stack_reverse_on_stack_with_one_element() {
|
||||
@ -238,6 +244,7 @@ void test_stack_reverse_on_stack_with_one_element() {
|
||||
|
||||
assert(stacks_equal(stack_reversed_stack, old_stack));
|
||||
|
||||
stack_free(stack_reversed_stack);
|
||||
stack_free(stack);
|
||||
}
|
||||
|
||||
@ -264,12 +271,14 @@ void test_stack_reverse_on_stack_with_more_than_one_element() {
|
||||
|
||||
assert(stacks_equal(unstack_reversed_stack, old_stack));
|
||||
|
||||
stack_free(unstack_reversed_stack);
|
||||
stack_free(stack_reversed_stack);
|
||||
stack_free(old_stack);
|
||||
stack_free(stack);
|
||||
}
|
||||
|
||||
void test_stack_reverse_should_not_change_stack() {
|
||||
struct stack *stack, *old_stack, *old_stack_address;
|
||||
struct stack *stack, *stack_reversed_stack_0, *stack_reversed_stack_1;
|
||||
struct card *card[3];
|
||||
|
||||
stack_malloc(&stack);
|
||||
@ -280,13 +289,14 @@ void test_stack_reverse_should_not_change_stack() {
|
||||
card_set(card[i], TWO + i, DIAMONDS + i, EXPOSED, 0, 0);
|
||||
stack_push(&stack, card[i]);
|
||||
}
|
||||
old_stack_address = stack;
|
||||
old_stack = stack_dup(stack);
|
||||
stack_reverse(stack);
|
||||
stack_reversed_stack_0 = stack_reverse(stack);
|
||||
stack_reversed_stack_1 = stack_reverse(stack_reversed_stack_0);
|
||||
|
||||
assert(stack == old_stack_address);
|
||||
assert(stacks_equal(stack, old_stack));
|
||||
assert(!stacks_equal(stack, stack_reversed_stack_0));
|
||||
assert(stacks_equal(stack, stack_reversed_stack_1));
|
||||
|
||||
stack_free(stack_reversed_stack_0);
|
||||
stack_free(stack_reversed_stack_1);
|
||||
stack_free(stack);
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,8 @@ void test_frames_equal_with_one_null() {
|
||||
frame_malloc(&frame);
|
||||
assert(!frames_equal(frame, NULL));
|
||||
assert(!frames_equal(NULL, frame));
|
||||
|
||||
frame_free(frame);
|
||||
}
|
||||
|
||||
void test_frames_equal_with_two_equivalent_frames() {
|
||||
@ -23,14 +25,20 @@ void test_frames_equal_with_two_equivalent_frames() {
|
||||
frame_set(frame_1, begin_y, begin_x);
|
||||
|
||||
assert(frames_equal(frame_0, frame_1));
|
||||
|
||||
frame_free(frame_0);
|
||||
frame_free(frame_1);
|
||||
}
|
||||
|
||||
void test_frames_equal_with_two_frame_pointers_to_the_same_address() {
|
||||
struct frame *frame;
|
||||
|
||||
frame_malloc(&frame);
|
||||
frame_init(frame);
|
||||
|
||||
assert(frames_equal(frame, frame));
|
||||
|
||||
frame_free(frame);
|
||||
}
|
||||
|
||||
void test_cards_equal_with_two_nulls() {
|
||||
@ -55,14 +63,20 @@ void test_cards_equal_with_two_equivalent_cards() {
|
||||
card_set(card_1, ACE, SPADES, EXPOSED, begin_y, begin_x);
|
||||
|
||||
assert(cards_equal(card_0, card_1));
|
||||
|
||||
card_free(card_0);
|
||||
card_free(card_1);
|
||||
}
|
||||
|
||||
void test_cards_equal_with_two_card_pointers_to_the_same_address() {
|
||||
struct card *card;
|
||||
|
||||
card_malloc(&card);
|
||||
card_init(card);
|
||||
|
||||
assert(cards_equal(card, card));
|
||||
|
||||
card_free(card);
|
||||
}
|
||||
|
||||
void test_stacks_equal_with_two_nulls() {
|
||||
@ -73,8 +87,12 @@ void test_stacks_equal_with_one_null() {
|
||||
struct stack *stack;
|
||||
|
||||
stack_malloc(&stack);
|
||||
stack_init(stack);
|
||||
|
||||
assert(!stacks_equal(stack, NULL));
|
||||
assert(!stacks_equal(NULL, stack));
|
||||
|
||||
stack_free(stack);
|
||||
}
|
||||
|
||||
void test_stacks_equal_with_two_equivalent_stacks() {
|
||||
@ -88,10 +106,15 @@ void test_stacks_equal_with_two_equivalent_stacks() {
|
||||
card_set(card_1, ACE, SPADES, EXPOSED, begin_y, begin_x);
|
||||
stack_malloc(&stack_0);
|
||||
stack_malloc(&stack_1);
|
||||
stack_init(stack_0);
|
||||
stack_init(stack_1);
|
||||
stack_push(&stack_0, card_0);
|
||||
stack_push(&stack_1, card_1);
|
||||
|
||||
assert(stacks_equal(stack_0, stack_1));
|
||||
|
||||
stack_free(stack_0);
|
||||
stack_free(stack_1);
|
||||
}
|
||||
|
||||
void test_stacks_equal_with_two_different_stacks() {
|
||||
@ -105,18 +128,26 @@ void test_stacks_equal_with_two_different_stacks() {
|
||||
card_set(card_1, KING, HEARTS, EXPOSED, begin_y, begin_x);
|
||||
stack_malloc(&stack_0);
|
||||
stack_malloc(&stack_1);
|
||||
stack_init(stack_0);
|
||||
stack_init(stack_1);
|
||||
stack_push(&stack_0, card_0);
|
||||
stack_push(&stack_1, card_1);
|
||||
|
||||
assert(!stacks_equal(stack_0, stack_1));
|
||||
|
||||
stack_free(stack_0);
|
||||
stack_free(stack_1);
|
||||
}
|
||||
|
||||
void test_stacks_equal_with_two_stack_pointers_to_the_same_address() {
|
||||
struct stack *stack;
|
||||
|
||||
stack_malloc(&stack);
|
||||
stack_init(stack);
|
||||
|
||||
assert(stacks_equal(stack, stack));
|
||||
|
||||
stack_free(stack);
|
||||
}
|
||||
|
||||
void test_test_helper() {
|
||||
|
Loading…
Reference in New Issue
Block a user