- If this is NOT the right forum for this post, please advise me, and my apologies in advance.

Trusting that this is the right place...

There is the Eight Queens problem (eight queens on a chessboard to be placed in such a manner that no queen attacks another). There are 92 solutions to this problem. How can one write tests for this problem (and other problems of similar nature)?

Thanks and regards.

Pradyumn Sharma

Pragati Software Pvt Ltd

207, Lok Center, Marol-Maroshi Road,

Andheri East, Mumbai 400 059. India

Tel: +91 22 3091 0000

www.pragatisoftware.com

www.twitter.com/PradyumnSharma

[Non-text portions of this message have been removed] - What have you tried so far?

You'll need to make your question more specific to what your current

focussed problem is.

With the information you've provided this sounds like you're looking for

something to solve your homework for you, which we won't do

On Tue, Jun 19, 2012 at 12:02 PM, Pradyumn Sharma <

pradyumn.sharma@...> wrote:

> **

--

>

>

> If this is NOT the right forum for this post, please advise me, and my

> apologies in advance.

>

> Trusting that this is the right place...

>

> There is the Eight Queens problem (eight queens on a chessboard to be

> placed in such a manner that no queen attacks another). There are 92

> solutions to this problem. How can one write tests for this problem (and

> other problems of similar nature)?

>

> Thanks and regards.

>

> Pradyumn Sharma

>

> Pragati Software Pvt Ltd

> 207, Lok Center, Marol-Maroshi Road,

> Andheri East, Mumbai 400 059. India

> Tel: +91 22 3091 0000

>

> www.pragatisoftware.com

> www.twitter.com/PradyumnSharma

>

> [Non-text portions of this message have been removed]

>

>

>

Maybe she awoke to see the roommate's boyfriend swinging from the

chandelier wearing a boar's head.

Something which you, I, and everyone else would call "Tuesday", of course.

[Non-text portions of this message have been removed] - Normally, the typical way to solve a problem like this would be to write

some code to see if the constraints of the problem are met. In this case,

go through the chess board, and when you find a queen, see if it is

attacking another queen. If it is, call Assert.fail(). The only tricky part

is finding a useful way to represent the chess board (and, possibly, making

the failure message print something useful).

Given that there are a few well-known solutions to this problem, however, I

would be tempted to do something more radical: see if the current board

matches one of the well known solutions.

Good luck,

-- Kevin

On Tue, Jun 19, 2012 at 4:02 AM, Pradyumn Sharma <

pradyumn.sharma@...> wrote:

> **

[Non-text portions of this message have been removed]

>

>

> If this is NOT the right forum for this post, please advise me, and my

> apologies in advance.

>

> Trusting that this is the right place...

>

> There is the Eight Queens problem (eight queens on a chessboard to be

> placed in such a manner that no queen attacks another). There are 92

> solutions to this problem. How can one write tests for this problem (and

> other problems of similar nature)?

>

> Thanks and regards.

>

> Pradyumn Sharma

>

> Pragati Software Pvt Ltd

> 207, Lok Center, Marol-Maroshi Road,

> Andheri East, Mumbai 400 059. India

> Tel: +91 22 3091 0000

>

> www.pragatisoftware.com

> www.twitter.com/PradyumnSharma

>

> [Non-text portions of this message have been removed]

>

>

>

- Pradyumn Sharma wrote on 19.6.2012 14:02:
> There is the Eight Queens problem (eight queens on a chessboard to be

You could write tests for low-level parts of the algorithm ("stepping

> placed in such a manner that no queen attacks another). There are 92

> solutions to this problem. How can one write tests for this problem (and

> other problems of similar nature)?

stones" as Kent Beck called them in

http://www.infoq.com/presentations/responsive-design), so that when

those parts are put together you will have the full algorithm.

Here is another problem which I solved using a similar algorithm as I've

earlier used for the Eight Queens problem:

"Diagram of Nine Places - Put the numbers 1 to 9 into the squares so it

adds to 15 whether you view it horizontally, vertically or diagonally."

_ _ _

|_|_|_|

|_|_|_|

|_|_|_|

My tests are at

https://github.com/orfjackal/misc-tools/blob/master/src/test/java/net/orfjackal/experimental/nineplaces/DiagramTest.java

and the solution at

https://github.com/orfjackal/misc-tools/tree/master/src/main/java/net/orfjackal/experimental/nineplaces

Of those tests noteworthy are Diagram_with_horizontal_failure,

Diagram_with_vertical_failure and Diagram_with_diagonal_failure. They

make sure that the Diagram class notices any violations of the rules.

After that it's just a matter of iterating the possible solutions and

backtracing when a rule is violated. I didn't write tests for the last

ten lines of code which put it all together (the DiagramOfNinePlaces

class), though it surely would be possible by abstracting the iterating

of possible solutions.

--

Esko Luontola

www.orfjackal.net - Hello,

You need to write a method to place the queens where they can't attack each other.Write a method using following algorithm which will return a list.

________________________________

From: Pradyumn Sharma <pradyumn.sharma@...>

To: junit@yahoogroups.com

Sent: Tuesday, 19 June 2012 7:02 AM

Subject: [junit] How to test program for "Eight Queens"

If this is NOT the right forum for this post, please advise me, and my apologies in advance.

Trusting that this is the right place...

There is the Eight Queens problem (eight queens on a chessboard to be placed in such a manner that no queen attacks another). There are 92 solutions to this problem. How can one write tests for this problem (and other problems of similar nature)?

Thanks and regards.

Pradyumn Sharma

Pragati Software Pvt Ltd

207, Lok Center, Marol-Maroshi Road,

Andheri East, Mumbai 400 059. India

Tel: +91 22 3091 0000

www.pragatisoftware.com

www.twitter.com/PradyumnSharma

[Non-text portions of this message have been removed]

1. If the remainder from dividing N by 6 is not 2 or 3 then the list is simply all even numbers followed by all odd numbers ≤ N

2. Otherwise, write separate lists of even and odd numbers (i.e. 2,4,6,8 - 1,3,5,7)

3. If the remainder is 2, swap 1 and 3 in odd list and move 5 to the end (i.e. 3,1,7,5)

4. If the remainder is 3, move 2 to the end of even list and 1,3 to the end of odd list (i.e. 4,6,8,2 - 5,7,9,1,3)

5. Append odd list to the even list and place queens in the rows given by these numbers, from left to right (i.e. a2, b4, c6, d8, e3, f1, g7, h5)

Where N is the number of queens.

Write a test method which will have the list hard coded and compare with the list which your method is returning.

I know I have not explained it very well but this might help you a little.Do let me know if you get succeed in writing.

Thanks,

Mihir

[Non-text portions of this message have been removed]