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 953029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:59:09+00:00 2026-05-15T23:59:09+00:00

So I made the following test for a class Board that would to be

  • 0

So I made the following test for a class Board that would to be born:

[TestMethod]
public void Set_The_Origin_As_Violet_And_The_Query_Confirms_It() {
    Board board = new Board(10, 10);

    Color expected = Color.Violet;
    board.SetColorAt(0, 0, expected);
    Color actual = board.GetColorAt(0, 0);
    Assert.AreEqual(expected, actual);
}

I tried running the code, but the compiler signaled that Board didn’t exist. So I created it.

I tried to run the code again, but it was of no avail, as both SetColorAt() and GetColorAt() methods didn’t exist. I created them:

public void SetColorAt(int x, int y, Color color) {
}

public void GetColorAt(int x, int y) {
}

Still, not everything was fine, as I had to return Color.Violet. So I changed GetColorAt() to

public void GetColorAt(int x, int y) {
    return Color.Violet;
}

So I got a green light for the first time.

What I want my final code to be on the class board is something of the form:

public class Board
{
    private Color[,] board;

    public Board(int x, int y)
    {
        board = new Color[x, y];
    }

    public void SetColorAt(int x, int y, Color color) {
        board[x, y] = color;
    }

    public Color GetColorAt(int x, int y) {
        return board[x, y];
    }
}

My first question is….

how to get there? Can I consider that in the “refactor” phase of the Unit-Test I have shown above, when removing duplication I will eventually end up with this code?

If the answer is yes, I feel that my Unit-test is testing something way too “localized” for what the code actually does. You see, the test is just checking for 1 pixel and one color, while the code itself is way more complex and rich.

Maybe the solution would be to add more Unit-Tests? Which would you advise to make?

My second question is…

I know later I’ll want to have an IBoard. Should I just express that in the above Unit-Test? Should I let

Board board = new Board(10, 10);

as it is and still create the IBoard interface? How to deal with this?

  • 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-05-15T23:59:10+00:00Added an answer on May 15, 2026 at 11:59 pm
    public void GetColorAt(int x, int y) {
        return Color.Violet;
    }
    

    The return Color.Violet statement here can be considered Data duplication, so you can refactor this bit out. The simplest thing that could possible work though would be having a single Color value that gets set when you call SetColorAt

    public class Board
    {
        private Color theColor;
    
        public Board(int x, int y)
        {
        }
    
        public void SetColorAt(int x, int y, Color color) {
            theColor = color;
        }
    
        public Color GetColorAt(int x, int y) {
            return theColor;
        }
    }
    

    Now, you’ll need more tests, to show you can set seperate cells to different colors.

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

Sidebar

Related Questions

I made a class that derives from Component: public class MyComponent: System.ComponentModel.Component { }
I have the following test-class made on the fly: http://sumoin.pastebin.com/ff744ea4 No fine-tuning or something
I have an application that is made up of the following: A central database
While discussing a Java synchronization question , someone made a comment that the following
I am trying to test that a particular method throws an expected exception from
I have the following ValidationRule class in WPF public class EmptyFieldValidationRule: BaseValidationRule { public
Let us assume I have a to be tested class that has the following
I have the following object: namespace LearnLINQ1 { [Table(Name=testMe)] public class SubmitTest { [Column(Name=FirstName)]
I am currently doing a code review and the following code made me jump.
I have roughly the following code. Could this be made nicer or more efficient?

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.