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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:38:11+00:00 2026-05-31T02:38:11+00:00

I am creating simple chess board game in java, and they are running smoothly,

  • 0

I am creating simple chess board game in java, and they are running smoothly, however i am getting 2 failures while testing and i don’t understand the logic behind them.

failure #1: player 1 has cloned his king and dominated expected <8> but it was <1>

failure #2: Symbols should be treated as an empty cells. expected <1> but it was <0>

that’s my code:

import java.io.ObjectInputStream.GetField;

public class ChessBoard {
    public static boolean belongsToPlayer(final char piece, final int player) { // method to check a piece is related to player 1 or 2
        if (player == 0 && Character.isUpperCase(piece)) {
            return true;
        }
        if (player == 1 && Character.isLowerCase(piece)) {
            return true;
        }
        return false;
    }

     public static int getCount(final String[] board, final int player) { // method to return the number of pieces belonging to each player
         int count = 0;

         if (board.length == 0) {
             return count = 0;
         }
         else if (board.length == 1) {
             return count = 1;
         }
         else {
        int size = board.length;
        for (int i = 1; i < size; i++) {        
            for (int j = 0; j < board[i].length(); j++) {

                if (belongsToPlayer(board[i].charAt(j), player)) {
                    count++;
                }
            }
        }
        }
        return count;
    }

}

and these are the test methods:
test #1
@Test(timeout = 1000)
    public void test8KingsPlayer1() {
        String[] board = {
                "kkkkkkkk"
            };
        assertEquals("Player 1 has cloned his king and has dominated", 
                8, instance.getCount(board, PLAYER1));
    }

test #2
@Test(timeout = 1000)
    public void testAPieceOfCode() {
        String[] board = {
                "int factorIal(int n) {",
                "    int n = 8, r = 1; ",
                "    while (n-- > 1)   ",
                "        r *= n;       ",
                "    return r;         ",
                "}                     "
            };
        assertEquals("Symbols should be treated as empty cells.", 
                1, instance.getCount(board, PLAYER0));
    }

anyone knows how to solve the problem?

  • 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-31T02:38:12+00:00Added an answer on May 31, 2026 at 2:38 am

    Failure 1:

    else if (board.length == 1) {
        return count = 1;
    }
    

    It returns 1 right away because you passed it a String[] with 1 element.

    Failure 2:

    for (int i = 1; i < size; i++) {
        ...
            if (belongsToPlayer(board[i] ...
    

    Array indexing starts at 0. You started with 1, which skips the first string in the array. Since the capital I was in the first row, it wasn’t counted.

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

Sidebar

Related Questions

getting error while creating simple maven project [WARNING] repository metadata for: 'org.apache.maven.plugins' could not
Im creating a simple message board with php/mysql. Users enter their name and a
Creating simple app using GAE / Django-nonrel (I don't think the problem is specific
I'm creating a simple game using HTML and CSS. I have a background image
I am creating a simple game designed to prompt the user for the Greek
Im creating a simple vehicle and projectile simulation game in WPF using C#. I
While creating a simple client for a REST service which I have stubbed out,
When creating a simple object hierarchy in Python, I'd like to be able to
Was creating a simple console application to do some prototyping and was shocked to
I'm creating a simple API that creates typed classes based on JSON data that

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.