Skip to content

Commit bfae48e

Browse files
extened BDD test cases
1 parent 61d611b commit bfae48e

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

code/tests/cases/test_bdd.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,63 @@ FOSSIL_TEST_CASE(xbdd_invalid_login) {
158158
}
159159
} // end of case
160160

161+
FOSSIL_TEST_CASE(xbdd_insufficient_balance) {
162+
GIVEN("a user's account with insufficient balance") {
163+
// Set up the context
164+
float accountBalance = 100.0;
165+
float withdrawalAmount = 200.0;
166+
167+
WHEN("the user requests a withdrawal of $200") {
168+
// Perform the withdrawal action
169+
bool withdrawalSuccess = false;
170+
if (accountBalance >= withdrawalAmount) {
171+
accountBalance -= withdrawalAmount;
172+
withdrawalSuccess = true;
173+
}
174+
175+
THEN("the withdrawal should fail and balance should remain unchanged") {
176+
// Check the expected outcome
177+
FOSSIL_TEST_ASSUME(!withdrawalSuccess, "Withdrawal should not succeed");
178+
FOSSIL_TEST_ASSUME(accountBalance == 100.0, "Account balance should remain unchanged");
179+
}
180+
}
181+
}
182+
} // end of case
183+
184+
FOSSIL_TEST_CASE(xbdd_add_multiple_items_to_cart) {
185+
GIVEN("a user with an empty shopping cart") {
186+
// Set up the context
187+
int cartItemCount = 0;
188+
189+
WHEN("the user adds three products to the cart") {
190+
// Perform the action of adding products
191+
cartItemCount += 3;
192+
193+
THEN("the cart item count should increase by 3") {
194+
// Check the expected outcome
195+
FOSSIL_TEST_ASSUME(cartItemCount == 3, "Cart item count should have increased by 3");
196+
}
197+
}
198+
}
199+
} // end of case
200+
201+
FOSSIL_TEST_CASE(xbdd_remove_item_from_cart) {
202+
GIVEN("a user with a shopping cart containing 2 items") {
203+
// Set up the context
204+
int cartItemCount = 2;
205+
206+
WHEN("the user removes one product from the cart") {
207+
// Perform the action of removing a product
208+
cartItemCount--;
209+
210+
THEN("the cart item count should decrease by 1") {
211+
// Check the expected outcome
212+
FOSSIL_TEST_ASSUME(cartItemCount == 1, "Cart item count should have decreased by 1");
213+
}
214+
}
215+
}
216+
} // end of case
217+
161218
// * * * * * * * * * * * * * * * * * * * * * * * *
162219
// * Fossil Logic Test Pool
163220
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -167,6 +224,9 @@ FOSSIL_TEST_GROUP(c_bdd_test_cases) {
167224
FOSSIL_TEST_ADD(bdd_suite, xbdd_empty_cart);
168225
FOSSIL_TEST_ADD(bdd_suite, xbdd_valid_login);
169226
FOSSIL_TEST_ADD(bdd_suite, xbdd_invalid_login);
227+
FOSSIL_TEST_ADD(bdd_suite, xbdd_insufficient_balance);
228+
FOSSIL_TEST_ADD(bdd_suite, xbdd_add_multiple_items_to_cart);
229+
FOSSIL_TEST_ADD(bdd_suite, xbdd_remove_item_from_cart);
170230

171231
FOSSIL_TEST_REGISTER(bdd_suite);
172232
} // end of group

code/tests/cases/test_bdd.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,63 @@ FOSSIL_TEST_CASE(cpp_xbdd_invalid_login) {
159159
}
160160
} // end of case
161161

162+
FOSSIL_TEST_CASE(cpp_xbdd_insufficient_balance) {
163+
GIVEN("a user's account with insufficient balance") {
164+
// Set up the context
165+
float accountBalance = 100.0;
166+
float withdrawalAmount = 200.0;
167+
168+
WHEN("the user requests a withdrawal of $200") {
169+
// Perform the withdrawal action
170+
bool withdrawalSuccess = false;
171+
if (accountBalance >= withdrawalAmount) {
172+
accountBalance -= withdrawalAmount;
173+
withdrawalSuccess = true;
174+
}
175+
176+
THEN("the withdrawal should fail and balance should remain unchanged") {
177+
// Check the expected outcome
178+
FOSSIL_TEST_ASSUME(!withdrawalSuccess, "Withdrawal should not succeed");
179+
FOSSIL_TEST_ASSUME(accountBalance == 100.0, "Account balance should remain unchanged");
180+
}
181+
}
182+
}
183+
} // end of case
184+
185+
FOSSIL_TEST_CASE(cpp_xbdd_add_multiple_items_to_cart) {
186+
GIVEN("a user with an empty shopping cart") {
187+
// Set up the context
188+
int cartItemCount = 0;
189+
190+
WHEN("the user adds three products to the cart") {
191+
// Perform the action of adding products
192+
cartItemCount += 3;
193+
194+
THEN("the cart item count should increase by 3") {
195+
// Check the expected outcome
196+
FOSSIL_TEST_ASSUME(cartItemCount == 3, "Cart item count should have increased by 3");
197+
}
198+
}
199+
}
200+
} // end of case
201+
202+
FOSSIL_TEST_CASE(cpp_xbdd_remove_item_from_cart) {
203+
GIVEN("a user with a shopping cart containing 2 items") {
204+
// Set up the context
205+
int cartItemCount = 2;
206+
207+
WHEN("the user removes one product from the cart") {
208+
// Perform the action of removing a product
209+
cartItemCount--;
210+
211+
THEN("the cart item count should decrease by 1") {
212+
// Check the expected outcome
213+
FOSSIL_TEST_ASSUME(cartItemCount == 1, "Cart item count should have decreased by 1");
214+
}
215+
}
216+
}
217+
} // end of case
218+
162219
// * * * * * * * * * * * * * * * * * * * * * * * *
163220
// * Fossil Logic Test Pool
164221
// * * * * * * * * * * * * * * * * * * * * * * * *
@@ -168,6 +225,9 @@ FOSSIL_TEST_GROUP(cpp_bdd_test_cases) {
168225
FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_empty_cart);
169226
FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_valid_login);
170227
FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_invalid_login);
228+
FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_insufficient_balance);
229+
FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_add_multiple_items_to_cart);
230+
FOSSIL_TEST_ADD(cpp_bdd_suite, cpp_xbdd_remove_item_from_cart);
171231

172232
FOSSIL_TEST_REGISTER(cpp_bdd_suite);
173233
} // end of group

0 commit comments

Comments
 (0)