Skip to content

Commit

Permalink
Move compile tests to files for easier management
Browse files Browse the repository at this point in the history
  • Loading branch information
ajami1331 committed Sep 28, 2024
1 parent e8ea518 commit f8a90db
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 88 deletions.
101 changes: 14 additions & 87 deletions IntegrationTest/CompileTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using DotNet.Testcontainers.Images;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Sojj;
using Sojj.Services;

Expand All @@ -17,98 +13,29 @@ public CompileTest(ContainerFixture fixture)
{
_sandBoxSerivce = fixture.SandBoxSerivce;
}
[Fact]
public async Task CheckHealthAsync()
{
await _sandBoxSerivce.CheckHealthAsync();
Assert.True(true);
}

[Fact]
public async Task CompileC()
{
string sourceCode = "#include <stdio.h>\nint main() { printf(\"Hello, World!\"); return 0; }";
var result = await _sandBoxSerivce.CompileAsync(sourceCode, Guid.NewGuid().ToString(), "c");
Assert.Equal(JudgeStatus.STATUS_ACCEPTED, result.Status);
}

[Fact]
public async Task CompileC11()
public static IEnumerable<object[]> TestData()
{
string sourceCode = "#include <stdio.h>\nint main() { printf(\"Hello, World!\"); return 0; }";
var result = await _sandBoxSerivce.CompileAsync(sourceCode, Guid.NewGuid().ToString(), "c11");
Assert.Equal(JudgeStatus.STATUS_ACCEPTED, result.Status);
}

[Fact]
public async Task CompileCC()
{
string sourceCode = "#include <cstdio>\nint main() { printf(\"Hello, World!\"); return 0; }";
var result = await _sandBoxSerivce.CompileAsync(sourceCode, Guid.NewGuid().ToString(), "cc");
Assert.Equal(JudgeStatus.STATUS_ACCEPTED, result.Status);
}

[Fact]
public async Task CompileCC11()
{
string sourceCode = "#include <cstdio>\nint main() { auto st = \"c++11\"; printf(\"Hello, World!\"); return 0; }";
var result = await _sandBoxSerivce.CompileAsync(sourceCode, Guid.NewGuid().ToString(), "cc11");
Assert.Equal(JudgeStatus.STATUS_ACCEPTED, result.Status);
}

[Fact]
public async Task CompileCC20()
{
string sourceCode = "#include <cstdio>\n#include <compare>\nint main() { int a = 91, b = 110; auto ans1 = a <=> b; printf(\"Hello, World!\"); return 0; }";
var result = await _sandBoxSerivce.CompileAsync(sourceCode, Guid.NewGuid().ToString(), "cc20");
Assert.Equal(JudgeStatus.STATUS_ACCEPTED, result.Status);
}

[Fact]
public async Task CompilePython3()
{
string sourceCode = "print('Hello, World!')";
var result = await _sandBoxSerivce.CompileAsync(sourceCode, Guid.NewGuid().ToString(), "py3");
Assert.Equal(JudgeStatus.STATUS_ACCEPTED, result.Status);
}

[Fact]
public async Task CompileJava()
{
string sourceCode = "public class Main { public static void main(String[] args) { System.out.println(\"Hello, World!\"); } }";
var result = await _sandBoxSerivce.CompileAsync(sourceCode, Guid.NewGuid().ToString(), "java");
Assert.Equal(JudgeStatus.STATUS_ACCEPTED, result.Status);
}

[Fact]
public async Task CompileJS()
{
string sourceCode = "console.log('Hello, World!')";
var result = await _sandBoxSerivce.CompileAsync(sourceCode, Guid.NewGuid().ToString(), "js");
Assert.Equal(JudgeStatus.STATUS_ACCEPTED, result.Status);
string path = Path.Combine(CommonDirectoryPath.GetSolutionDirectory().DirectoryPath, "testdata", "compile-test");
foreach (string file in Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories))
{
string ext = Path.GetExtension(file).Substring(1);
yield return new object[] { ext, File.ReadAllText(file) };
}
}

[Fact]
public async Task CompileCSharp()
{
string sourceCode = "using System; class Program { static void Main() { Console.WriteLine(\"Hello, World!\"); } }";
var result = await _sandBoxSerivce.CompileAsync(sourceCode, Guid.NewGuid().ToString(), "cs");
Assert.Equal(JudgeStatus.STATUS_ACCEPTED, result.Status);
}

[Fact]
public async Task CompileRuby()
public async Task CheckHealthAsync()
{
string sourceCode = "puts 'Hello, World!'";
var result = await _sandBoxSerivce.CompileAsync(sourceCode, Guid.NewGuid().ToString(), "ruby");
Assert.Equal(JudgeStatus.STATUS_ACCEPTED, result.Status);
await _sandBoxSerivce.CheckHealthAsync();
Assert.True(true);
}

[Fact]
public async Task CompileKotlin()
[Theory]
[MemberData(nameof(TestData))]
public async Task CompileCodeAsync(string lang, string sourceCode)
{
string sourceCode = "fun main() { println(\"Hello, World!\") }";
var result = await _sandBoxSerivce.CompileAsync(sourceCode, Guid.NewGuid().ToString(), "kt");
var result = await _sandBoxSerivce.CompileAsync(sourceCode, Guid.NewGuid().ToString(), lang);
Assert.Equal(JudgeStatus.STATUS_ACCEPTED, result.Status);
}
}
1 change: 0 additions & 1 deletion IntegrationTest/ContainerCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

[CollectionDefinition("ContainerCollection")]
public class ContainerCollection : ICollectionFixture<ContainerFixture>
{
Expand Down
6 changes: 6 additions & 0 deletions testdata/compile-test/1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>

int main() {
printf("Hello, world!\n");
return 0;
}
7 changes: 7 additions & 0 deletions testdata/compile-test/1.c11
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>
#include <stdnoreturn.h>

int main() {
printf("Hello, world!\n");
return 0;
}
8 changes: 8 additions & 0 deletions testdata/compile-test/1.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <cstdio>
#include <iostream>

int main() {
printf("Hello, world!\n");
std::cout << "Hello, world!" << std::endl;
return 0;
}
9 changes: 9 additions & 0 deletions testdata/compile-test/1.cc11
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <cstdio>
#include <iostream>

int main() {
auto s = "Hello, world!\n";
printf("Hello, world!\n");
std::cout << "Hello, world!" << std::endl;
return 0;
}
10 changes: 10 additions & 0 deletions testdata/compile-test/1.cc20
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <cstdio>
#include <iostream>

int main() {
auto s = "Hello, world!\n";
printf("Hello, world!\n");
std::cout << "Hello, world!" << std::endl;
int a = 91, b = 110; auto ans1 = a <=> b;
return 0;
}
7 changes: 7 additions & 0 deletions testdata/compile-test/1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System;
class Program
{
static void Main() {
Console.WriteLine("Hello, World!");
}
}
5 changes: 5 additions & 0 deletions testdata/compile-test/1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
1 change: 1 addition & 0 deletions testdata/compile-test/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello world');
3 changes: 3 additions & 0 deletions testdata/compile-test/1.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fun main() {
println("Hello, World!")
}
1 change: 1 addition & 0 deletions testdata/compile-test/1.py3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello, World!")
Empty file added testdata/compile-test/1.ruby
Empty file.

0 comments on commit f8a90db

Please sign in to comment.