私はTDDとC++の新入生で、いくつかのコード作品を書いていますが、それは醜いようです...
これらのコードをリファクタリングする方法についてのヒントを教えてください。
私は次のようなテストケースを定義します。
// define some test case
namespace test_case_planes {
const std::string t_filename = "planes.segy_first_trace";
boost::uintmax_t t_file_size = 5888;
boost::uintmax_t t_traces_size = 1;
boost::int16_t t_trace_samples_size = 512;
boost::int16_t t_sample_interval = 4000; // 2000us, 2ms
}
namespace test_case_ld0042_file_00018 {
const std::string t_filename = "ld0042_file_00018.sgy_first_trace";
boost::uintmax_t t_file_size = 12040;
boost::uintmax_t t_traces_size = 1;
boost::int16_t t_trace_samples_size = 2050;
boost::int16_t t_sample_interval = 2000; // 2000us, 2ms
}
そしてこのようにテストします(グーグルテストで)
TEST(Segy, constructWithNoParas){
using namespace test_case_planes;
segy::Segy* test_segy = new segy::Segy();
EXPECT_EQ(test_segy->getFilename(), t_filename);
}
TEST(Segy, constructWithFilename){
using namespace test_case_ld0042_file_00018;
segy::Segy* test_segy = new segy::Segy(t_filename);
EXPECT_EQ(test_segy->getFilename(), t_filename);
}
TEST(Segy, setFilename){
using namespace test_case_ld0042_file_00018;
segy::Segy* test_segy = new segy::Segy();
test_segy->setFilename(t_filename);
EXPECT_EQ(test_segy->getFilename(), t_filename);
}