Skip to content

Commit

Permalink
Merge pull request #93 from FherStk:v2.17.1
Browse files Browse the repository at this point in the history
V2.17.1
  • Loading branch information
FherStk authored Jan 29, 2022
2 parents 4d6ba11 + f5969b1 commit 1930d06
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 64 deletions.
2 changes: 1 addition & 1 deletion core/AutoCheck.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Authors>Fernando Porrino Serrano</Authors>
<Product>AutoCheck.Core</Product>
<Copyright>Copyright © 2022</Copyright>
<VersionPrefix>2.17.0</VersionPrefix>
<VersionPrefix>2.17.1</VersionPrefix>
<VersionSuffix>stable</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<AssemblyFileVersion>$(AssemblyVersion)</AssemblyFileVersion>
Expand Down
18 changes: 10 additions & 8 deletions core/connectors/Csv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CsvDocument{
//TODO: use some library...
private char FielDelimiter {get; set;}

private char TextDelimiter {get; set;}
private char? TextDelimiter {get; set;}

/// <summary>
/// All the content, grouped by columns.
Expand Down Expand Up @@ -68,7 +68,7 @@ public int Count {
/// <param name="fieldDelimiter">Field delimiter char.</param>
/// <param name="textDelimiter">Text delimiter char.</param>
/// <param name="headers">True if the first row are headers.</param>
public CsvDocument(string file, char fieldDelimiter=',', char textDelimiter='"', bool headers = true){
public CsvDocument(string file, char fieldDelimiter=',', char? textDelimiter='"', bool headers = true){
this.FielDelimiter = fieldDelimiter;
this.TextDelimiter = textDelimiter;

Expand All @@ -94,10 +94,12 @@ public CsvDocument(string file, char fieldDelimiter=',', char textDelimiter='"',
for(int i = 0; i < items.Length; i++){
string item = items[i];

if(item.StartsWith(this.TextDelimiter) && item.EndsWith(this.TextDelimiter)){
//Removing string delimiters
item = item.Trim(TextDelimiter);
}
if(this.TextDelimiter.HasValue){
if(item.StartsWith(this.TextDelimiter.Value) && item.EndsWith(this.TextDelimiter.Value)){
//Removing string delimiters
item = item.Trim(TextDelimiter.Value);
}
}

this.Content[this.Content.Keys.ElementAt(i)].Add(item);
}
Expand Down Expand Up @@ -175,7 +177,7 @@ public class Csv: Base{
/// <param name="fieldDelimiter">Field delimiter char.</param>
/// <param name="textDelimiter">Text delimiter char.</param>
/// <param name="headers">True if the first row are headers.</param>
public Csv(string filePath, char fieldDelimiter=',', char textDelimiter='"', bool headers = true){
public Csv(string filePath, char fieldDelimiter=',', char? textDelimiter='"', bool headers = true){
Parse(filePath, fieldDelimiter, textDelimiter, headers);
}

Expand Down Expand Up @@ -211,7 +213,7 @@ public Csv(Utils.OS remoteOS, string host, string username, string password, int
public Csv(Utils.OS remoteOS, string host, string username, string password, string filePath, char fieldDelimiter=',', char textDelimiter='"', bool headers = true): this(remoteOS, host, username, password, 22, filePath, fieldDelimiter, textDelimiter, headers){
}

private void Parse(string filePath, char fieldDelimiter=',', char textDelimiter='"', bool headers = true){
private void Parse(string filePath, char fieldDelimiter=',', char? textDelimiter='"', bool headers = true){
if(string.IsNullOrEmpty(filePath)) throw new ArgumentNullException("filePath");
if(!File.Exists(filePath)) throw new FileNotFoundException();

Expand Down
16 changes: 10 additions & 6 deletions core/copy/PlainText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ namespace AutoCheck.Core.CopyDetectors{
/// </summary>
public class PlainText: Base{
protected class File{
public string Folder {get; set;}
public string Path {get; set;}
public string FolderPath {get; set;}
public string FolderName {get; set;}
public string FilePath {get; set;}
public string FileName {get; set;}
public int WordCount {get; set;}
public int LineCount {get; set;}
public List<string> Content {get; set;}
Expand All @@ -41,8 +43,10 @@ public File(string folder, string file){

WordCount = Content.SelectMany(x => x.Split(" ")).Count();
LineCount = Content.Count();
Folder = folder;
Path = file;
FolderPath = folder;
FolderName = System.IO.Path.GetFileName(folder);
FilePath = file;
FileName = System.IO.Path.GetFileName(file);
}

public override string ToString(){
Expand Down Expand Up @@ -189,10 +193,10 @@ public override (string Folder, string File, (string Folder, string File, float
int i = Index[path];
var matches = new List<(string, string, float)>();
for(int j=0; j < Files.Count(); j++){
if(i != j) matches.Add((Files[j].Folder, Files[j].Path, Matches[i,j]));
if(i != j) matches.Add((Files[j].FolderPath, Files[j].FilePath, Matches[i,j]));
}

return (Files[i].Folder, Files[i].Path, matches.ToArray());
return (Files[i].FolderPath, Files[i].FilePath, matches.ToArray());
}
}
}
12 changes: 6 additions & 6 deletions core/copy/SourceCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ public override void Compare(){
//JPlag uses one single path
var path = GetMinimalPath(Files);
var shell = new Connectors.Shell();
var output = Path.Combine(Utils.TempFolder, DateTime.Now.ToString("yyyyMMddhhhhMMssffff"));
var output = Path.Combine(Utils.TempFolder, $@"{Guid.NewGuid()}");
if(!Directory.Exists(output)) Directory.CreateDirectory(output);

try{
//Setting up execution
var lang = Path.GetExtension(FilePattern).TrimStart('.');
var result = shell.RunCommand($"java -jar jplag-3.0.0-jar-with-dependencies.jar -r {output} -l {lang} {path}", Utils.UtilsFolder);
var result = shell.RunCommand($"java -jar jplag-3.0.0-jar-with-dependencies.jar -r \"{output}\" -l {lang} \"{path}\"", Utils.UtilsFolder);

//Parsing result (JPlag creates a CSV file with the output data)
var csv = new Connectors.Csv(Path.Combine(output, "matches_avg.csv"), ';', ' ', false);
var csv = new Connectors.Csv(Path.Combine(output, "matches_avg.csv"), ';', null, false);
var folders = new Dictionary<string, int>();

//temp directory to match the JPlag directory name with the original index (directory path)
foreach(var key in Index.Keys){
folders.Add(Path.GetFileName(key).Replace(" ", ""), Index[key]);
folders.Add(Path.GetFileName(key).Trim(), Index[key]);
}

//collecting matches
Expand Down Expand Up @@ -110,9 +110,9 @@ public override bool CopyDetected(string path){
}

private string GetMinimalPath(List<File> paths){
var left = paths.FirstOrDefault().Folder;
var left = paths.FirstOrDefault().FolderPath;
foreach(var right in paths.Skip(1)){
left = GetMinimalPath(left, right.Folder);
left = GetMinimalPath(left, right.FolderPath);
}

return left;
Expand Down
54 changes: 27 additions & 27 deletions scripts/templates/mineseeker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with AutoCheck. If not, see <https://www.gnu.org/licenses/>.

name: "DAM - M03 (UF1): Mineseeker"
version: "1.0.1.0"
version: "1.0.1.2"

#TODO: sacar las preguntas de dentro de la primera y hacer un ABORT si no compila.
# arreglar fallo en codigo fuente al poner minas en casillas ocupadas
Expand Down Expand Up @@ -55,7 +55,7 @@ body:

- run:
caption: "Compiling the file ~{$FILENAME}... "
command: "javac {$FILEPATH}"
command: javac "{$FILEPATH}"
expected: ""
onexception: "ABORT"

Expand All @@ -64,68 +64,68 @@ body:
content:
- run:
caption: "Checking the caption... "
command: "echo 3 | java {$FILEPATH}"
command: echo 3 | java "{$FILEPATH}"
expected: "%Escull una opció:%"

- run:
caption: "Checking the first option... "
command: "echo 3 | java {$FILEPATH}"
command: echo 3 | java "{$FILEPATH}"
expected: "%1. Emplenar el taulell%"

- run:
caption: "Checking the second option... "
command: "echo 3 | java {$FILEPATH}"
command: echo 3 | java "{$FILEPATH}"
expected: "%2. Mostrar el taulell%"

- run:
caption: "Checking the third option... "
command: "echo 3 | java {$FILEPATH}"
command: echo 3 | java "{$FILEPATH}"
expected: "%3. Sortir%"

- question:
description: "Input data"
content:
- run:
caption: "Checking the input data giving no data... "
command: "echo 1 | java {$FILEPATH}"
command: echo 1 | java "{$FILEPATH}"
expected: "Exception%"

- run:
caption: "Checking the input data giving rows... "
command: "echo 1 5 | java {$FILEPATH}"
command: echo 1 5 | java "{$FILEPATH}"
expected: "Exception%"

- run:
caption: "Checking the input data giving rows and columns... "
command: "echo 1 5 4 | java {$FILEPATH}"
command: echo 1 5 4 | java "{$FILEPATH}"
expected: "Exception%"

- run:
caption: "Checking the input question for the rows... "
command: "echo 1 5 4 1 3 | java {$FILEPATH}"
command: echo 1 5 4 1 3 | java "{$FILEPATH}"
expected: "%De quantes files vols el taulell?%"

- run:
caption: "Checking the input question for the columns... "
command: "echo 1 5 4 1 3 | java {$FILEPATH}"
command: echo 1 5 4 1 3 | java "{$FILEPATH}"
expected: "%De quantes columnes vols el taulell?%"

- run:
caption: "Checking the input question for the mines... "
command: "echo 1 5 4 1 3 | java {$FILEPATH}"
command: echo 1 5 4 1 3 | java "{$FILEPATH}"
expected: "%Quantes mines vols al taulell?%"
- question:
description: "Data verification"
score: 0.5
content:
- run:
caption: "Checking that more mines that cells is not allowed... "
command: "echo 1 1 1 2 3 | java {$FILEPATH}"
command: echo 1 1 1 2 3 | java "{$FILEPATH}"
expected: "%NO ES PODEN POSAR MÉS MINES QUE CASELLES%"

- connector:
type: "PlainText"
arguments: "--filePath {$FILEPATH}"
arguments: --filePath "{$FILEPATH}"

- question:
description: "Board internal creation"
Expand Down Expand Up @@ -171,14 +171,14 @@ body:
content:
- run:
caption: "Checking the return to the main menu... "
command: "echo 1 5 4 1 3 | java {$FILEPATH}"
command: echo 1 5 4 1 3 | java "{$FILEPATH}"
expected: "%Escull una opció:%"

- question:
description: "Displaying board's empty cells"
content:
- run:
command: "echo 1 1 1 0 2 3 | java {$FILEPATH}"
command: echo 1 1 1 0 2 3 | java "{$FILEPATH}"

- run:
caption: "Checking the display for a 1x1 board with no mines... "
Expand All @@ -188,7 +188,7 @@ body:
expected: "1"

- run:
command: "echo 1 5 3 0 2 3 | java {$FILEPATH}"
command: echo 1 5 3 0 2 3 | java "{$FILEPATH}"

- run:
caption: "Checking the display for a 5x3 board with no mines... "
Expand All @@ -198,7 +198,7 @@ body:
expected: "1"

- run:
command: "echo 1 3 5 0 2 3 | java {$FILEPATH}"
command: echo 1 3 5 0 2 3 | java "{$FILEPATH}"

- run:
caption: "Checking the display for a 3x5 board with no mines... "
Expand All @@ -208,7 +208,7 @@ body:
expected: "1"

- run:
command: "echo 1 5 5 0 2 3 | java {$FILEPATH}"
command: echo 1 5 5 0 2 3 | java "{$FILEPATH}"

- run:
caption: "Checking the display for a 5x5 board with no mines... "
Expand All @@ -221,7 +221,7 @@ body:
description: "Displaying board's mine cells"
content:
- run:
command: "echo 1 1 1 1 2 3 | java {$FILEPATH}"
command: echo 1 1 1 1 2 3 | java "{$FILEPATH}"

- run:
caption: "Checking the display for a 1x1 board full of mines... "
Expand All @@ -231,7 +231,7 @@ body:
expected: "1"

- run:
command: "echo 1 5 3 15 2 3 | java {$FILEPATH}"
command: echo 1 5 3 15 2 3 | java "{$FILEPATH}"

- run:
caption: "Checking the display for a 5x3 board full of mines... "
Expand All @@ -241,7 +241,7 @@ body:
expected: "1"

- run:
command: "echo 1 3 5 15 2 3 | java {$FILEPATH}"
command: echo 1 3 5 15 2 3 | java "{$FILEPATH}"

- run:
caption: "Checking the display for a 3x5 board full of mines... "
Expand All @@ -251,21 +251,21 @@ body:
expected: "1"

- run:
command: "echo 1 5 5 25 2 3 | java {$FILEPATH}"
command: echo 1 10 10 100 2 3 | java "{$FILEPATH}"

- run:
caption: "Checking the display for a 5x5 board full of mines... "
caption: "Checking the display for a 10x10 board full of mines... "
connector: "TextStream"
command: "Count"
arguments: --content {$RESULT} --regex "((?:\[O\]\s?){4}\[O\]\s*(?:\n|\\n)){5}"
arguments: --content {$RESULT} --regex "((?:\[O\]\s?){9}\[O\]\s*(?:\n|\\n)){10}"
expected: "1"

- question:
description: "Displaying empty board message"
content:
- run:
caption: "Checking the empty message... "
command: "echo 2 3 | java {$FILEPATH}"
command: echo 2 3 | java "{$FILEPATH}"
expected: "%HA CREAT CAP TAULELL%" #' (written) and ’ (copied from the statement) must be accepted "%NO S’HA CREAT CAP TAULELL%"

- question:
Expand All @@ -274,5 +274,5 @@ body:
content:
- run:
caption: "Checking the menu display... "
command: "echo 2 3 | java {$FILEPATH}"
command: echo 2 3 | java "{$FILEPATH}"
expected: "%Escull una opció:%"
Loading

0 comments on commit 1930d06

Please sign in to comment.