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

  • SEARCH
  • Home
  • 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 957799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:45:52+00:00 2026-05-16T00:45:52+00:00

This question comes a bit as continuation of the following topic (you don’t need

  • 0

This question comes a bit as continuation of the following topic (you don’t need to read it, though). It’s just a game of Tetris I’m implementing with TDD.

So here is the problem: I have a set of Acceptance tests. I have defined the following test in one of them:

[TestMethod]
public void I_Can_Query_Any_Piece_Of_The_Board_For_A_Color() {
    StandardTetris tetris = new StandardTetris();

    for (int y = 0; y < tetris.BoardSize.Height; ++y) {
        for (int x = 0; x < tetris.BoardSize.Width; ++x) {
            Color color = tetris.GetColorAt(x, y);

            Assert.IsTrue(
                color == Color.Cyan ||
                color == Color.Blue ||
                color == Color.Orange ||
                color == Color.Yellow ||
                color == Color.Green ||
                color == Color.Violet ||
                color == Color.Red
                );
        }
    }
}

which made me change a method I had on StandardTetris

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

to

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

The next test I’d like to do on was setting a couple of pixels to some colors, and then checking if they are indeed with that color in the positions I put them(although, now that I think of it, that would not be acceptance tests).
How can I do that?
StandardTetris doesn’t provide any kind of setter for the board pieces(not it is supposed to do it!) and I don’t want to have any other constructor than the default one. How can I mock it, then?


This is the current code on StandardTetris:

public class StandardTetris
{
    private static readonly int BOARD_WIDTH = 10;
    private static readonly int BOARD_HEIGHT = 22;

    private Size boardSize = new Size(BOARD_WIDTH, BOARD_HEIGHT);

    public Size BoardSize { get { return boardSize; } }

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

and by using your suggestions, I made the following test:

    [TestMethod]
    public void Set_A_Blue_2x2_Square_On_Origin_And_Query_It_Sucessfully() {
        Board board = new Board();
        board.SetColorAt(0, 0, Color.Blue);
        board.SetColorAt(0, 1, Color.Blue);
        board.SetColorAt(1, 0, Color.Blue);
        board.SetColorAt(1, 1, Color.Blue);

        Tetris tetris = new Tetris(board);

        Assert.AreEqual(Color.Blue, tetris.GetColorAt(0, 0));
        Assert.AreEqual(Color.Blue, tetris.GetColorAt(1, 0));
        Assert.AreEqual(Color.Blue, tetris.GetColorAt(0, 1));
        Assert.AreEqual(Color.Blue, tetris.GetColorAt(1, 1));
    }
  • 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-16T00:45:53+00:00Added an answer on May 16, 2026 at 12:45 am

    I see two options:

    • Create a second constructor where you can pass in pre-constructed information.

    • Create a test class TestStandardTetris that inherits from StandardTetris where the only difference is TestStandardTetris has the constructor for taking the pre-constructed information.

    Your tests are saying to you that you need a way to set the state, and you’re saying you don’t want the state to change, hence the lack of a setter, so the only place left to set the state is the constructor.

    The first option opens it up to the game’s main API.

    The second only opens it up to tests, and any future person who works with your API who decides to inherit from StandardTetris, it will also allow you test the functionality of StandardTetris if the only thing that’s changed is adding the constructor to TestStandardTetris

    There are probably other and better ways of doing this, so wait to see if any one else comes up with a better answer. 🙂

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

Sidebar

Related Questions

This may be a bit of daft question, but I don't come from an
Check this example before reading the question - http://www.sqlfiddle.com/#!2/fcf3e/8 The following data comes from
(I've read a lot about 64-bit versus 32-bit OS/Apps, but this question is specifically
Okay, this question comes through a friend so it might be lost in translation...
( Late edit: This question will hopefully be obsolete when Java 7 comes, because
Just come up with this question. Any hint?
This is a bit of subjective question about a specific situation. Main goal for
The question plot (a bit abstract, but answering this question will help me in
First of all I apologize in advance for this question, a bit off the
enter code here i'm a bit newbie, so sorry for this question. i have

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.