-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
Hi @MchKosticyn,
For the following input, I am not seeing tests for the "true branches" for CheckSolution(), please try this out and let me know, thanks again.
$ cat testgen.bat
dotnet ..\..\..\testGen\upstream\VSharp\VSharp.Runner\bin\Release\net7.0\VSharp.Runner.dll --method CheckSolution bin\Debug\net6.0\BranchesAndLoops.dll -t 90 -o ..\out --render-tests --run-tests -v Trace
samiull@DESKTOP-OS5I16B MINGW64 /d/Users/samiull/Documents/2023/testgen/testgen/csharp/branches-quickstart
$ cat EightQueens.cs
using System;
namespace BranchesAndLoops
{
public class EightQueens
{
private readonly int[][] _board;
private const int N = 8;
public EightQueens(int[][] board)
{
this._board = board;
if (board.Length != N*N)
{
throw new ArgumentException("Board length is not 64");
}
}
private bool IsSafe(int row, int col)
{
// check if there is a queen in the same row to the
// left
for (int x = 0; x < col; x++)
if (_board[row][x] == 1)
return false;
// check if there is a queen in the upper left
// diagonal
for (int x = row, y = col; x >= 0 && y >= 0;
x--, y--)
if (_board[x][y] == 1)
return false;
// check if there is a queen in the lower left
// diagonal
for (int x = row, y = col; x < N && y >= 0;
x++, y--)
if (_board[x][y] == 1)
return false;
// if there is no queen in any of the above
// positions, then it is safe to place a queen
return true;
}
public bool CheckSolution()
{
if (this._board.Length == 0)
{
Console.WriteLine("Return false");
return false;
}
int numQueens = 0;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
if (_board[i][j] == 1)
{
numQueens++;
}
}
}
if (numQueens != N)
{
return false;
}
for (int row = 0; row < this._board.Length/2; row++)
{
for (int col = 0; col < this._board.Length/2; col++)
{
if (!IsSafe(row, col))
{
Console.WriteLine("Return false");
return false;
}
}
}
Console.WriteLine("Return true");
return true;
}
}
}
Activity
MchKosticyn commentedon May 4, 2024
Hi @smhmhmd
Actually I don't see 'return true' branch either. That happens, because every loop bound is symbolic, so symbolic execution creates new symbolic state on each loop iteration. This leads to exponential growth of symbolic states. This is main problem of symbolic execution.
Will try to fix that.
smhmhmd commentedon May 10, 2024
Hi @MchKosticyn
Where can I add prints to print all the states ? Is it possible to use a heuristic to protect against exponential growth of symbolic states ?
MchKosticyn commentedon May 15, 2024
Hi @smhmhmd
If you want to print all states, which are complete exploration, you can do it inside "Explorer.fs:reportState" function. But there are so many symbolic states...
About heuristics, searching strategy is exactly it. I already tried every strategy and cannot reach 'return true' branch.
Will try to modify strategies later.
smhmhmd commentedon May 15, 2024
Hi @MchKosticyn
The input code above is adapted from https://www.geeksforgeeks.org/8-queen-problem/, need to check if the input code is satisfiable.
MchKosticyn commentedon May 15, 2024
Hi @smhmhmd
Branch 'return true' is reachable, here is example:
But there is a bug inside constructor: check should be
board.Length != N
, because 'board' is not multidimensional array, it is array of arrays.smhmhmd commentedon May 15, 2024
Hi @MchKosticyn
Thanks for running it. So it is satisfiable although it is not an 8-queens solution.
The generated test would be the solution you added above.
I changed 'N*N' to 'N' and rebuilt, but the 'true' branch issue persists.
Generated test:
smhmhmd commentedon May 16, 2024
Hi @MchKosticyn
In the sample code below, I have both Mono.cecil and System.Reflection, Mono.cecil works and System.Reflection has this error