Last active
January 31, 2018 17:27
-
-
Save lithiumhead/8aebd2db647b7a58b83d95d8188579f8 to your computer and use it in GitHub Desktop.
TEST_P() and code in same file - Test Fail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <gtest/gtest.h> | |
struct BankAccount { | |
int balance = 0; | |
BankAccount() { | |
} | |
explicit BankAccount(const int balance) | |
: balance{balance} { | |
} | |
void deposit(int amount) { | |
balance += amount; | |
} | |
bool withdraw(int amount) { | |
} | |
}; | |
struct BankAccountTest : testing::Test { | |
BankAccount *account; | |
BankAccountTest() { | |
account = new BankAccount; | |
} | |
virtual ~BankAccountTest() { | |
delete account; | |
} | |
}; | |
struct account_state { | |
int initial_balance; | |
int withdrawal_amount; | |
int final_balance; | |
bool success; | |
}; | |
struct withdrawAccountTest : BankAccountTest , testing::WithParamInterface<account_state> { | |
withdrawAccountTest() { | |
account->balance = GetParam().initial_balance; | |
} | |
}; | |
TEST_P(withdrawAccountTest, FinalBalance) { | |
auto as = GetParam(); | |
auto success = account->withdraw(as.withdrawal_amount); | |
EXPECT_EQ(as.final_balance,account->balance); | |
EXPECT_EQ(as.success,success); | |
} | |
INSTANTIATE_TEST_CASE_P(Default, withdrawAccountTest, | |
testing::Values( | |
account_state{100,50,50,true}, | |
account_state{100,200,100,false} | |
)); | |
int main(int argc, char **argv) { | |
::testing::InitGoogleTest(&argc, argv); | |
return RUN_ALL_TESTS(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment