Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8831891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:24:39+00:00 2026-06-14T08:24:39+00:00

I am a freshman of TDD and C++, I write some code works but

  • 0

I am a freshman of TDD and C++, I write some code works but it seems ugly…

could you give me some tips on how to refactor these code?

I define testcases like this:

// 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
}

and test like this(with google test)

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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:24:40+00:00Added an answer on June 14, 2026 at 8:24 am

    I think what you are looking for is a fixture. I am not familiar with google test, but test fixtures should be available in most test frameworks. You should look into the documentation for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a freshman in high-school who has some time on his hands, and
everyone. I'm trying to give a text link a background image but I'm not
I'm a freshman to jQuery. I think it's reasonable that jQuery could manipulate elements
I'm a college CS freshman who wishes to learn a version control system well.
I'm a freshman in college going for my computer science degree... I've programmed plenty
I’m a freshman on Ruby and now trying to install ruby on my machine
I was thinking back to my freshman year at college (five years ago) when
I've taken a course in C++ in my freshman year in undergrad. However once
As a big fan of Charles Petzold's books Code and The Annotated Turing I
I need to programmely switch the current user to another,then the followed code should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.