From 3deb14097cb1d5847cf1dc5d6434287ea4c2626a Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Mon, 24 Jun 2024 23:17:41 -0500 Subject: [PATCH] Begin csharp port --- .github/workflows/on_push.yml | 30 ++++++++++++++++++++++++- Makefile | 5 ++++- csharp/Makefile | 10 +++++++++ csharp/README.md | 41 +++++++++++++++++++++++++++++++++++ csharp/csharp.csproj | 27 +++++++++++++++++++++++ csharp/include/primes.cs | 0 csharp/p0000_template.cs | 0 csharp/test.cs | 0 8 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 csharp/Makefile create mode 100644 csharp/README.md create mode 100644 csharp/csharp.csproj create mode 100644 csharp/include/primes.cs create mode 100644 csharp/p0000_template.cs create mode 100644 csharp/test.cs diff --git a/.github/workflows/on_push.yml b/.github/workflows/on_push.yml index a390d4b3..91f0bc61 100644 --- a/.github/workflows/on_push.yml +++ b/.github/workflows/on_push.yml @@ -109,7 +109,6 @@ jobs: c: strategy: - fail-fast: false matrix: # compiler: ["llvm", "gcc"] # # compiler targets (ideally): clang, gcc, MSVCC, pcc, tcc, icc, @@ -144,3 +143,32 @@ jobs: - name: Run tests run: make ctest + + csharp: + strategy: + fail-fast: false + matrix: + net_version: [5, 6, 7, 8] + os: [ubuntu-latest, windows-latest] + include: + - net_version: 8 + os: macos-latest + - net_version: 8 + os: macos-13 + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v3 + + - name: Setup .NET ${{ matrix.net_version }} + uses: actions/setup-dotnet@v3 + with: + dotnet-version: ${{ matrix.net_version }} + cache: true + cache-dependency-path: 'csharp/packages.lock.json' + + - name: Dependencies + run: make csdependencies + + - name: Run Tests + run: make cstest diff --git a/Makefile b/Makefile index 11783a83..9f31a72a 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,11 @@ py%: c%: cd c && $(MAKE) $* $(MFLAGS) +cs%: + cd csharp && $(MAKE) $* $(MFLAGS) + js%: cd javascript && $(MAKE) $* $(MFLAGS) %: - $(MAKE) c$* js$* py$* $(MFLAGS) + $(MAKE) c$* cs$* js$* py$* $(MFLAGS) diff --git a/csharp/Makefile b/csharp/Makefile new file mode 100644 index 00000000..cb77dbc5 --- /dev/null +++ b/csharp/Makefile @@ -0,0 +1,10 @@ +test: dependencies + dotnet test + +test_%: dependencies + echo "WARNING: multithreaded tests not supported on javascript" + $(MAKE) test + +dependencies: + dotnet restore + diff --git a/csharp/README.md b/csharp/README.md new file mode 100644 index 00000000..cbc152ef --- /dev/null +++ b/csharp/README.md @@ -0,0 +1,41 @@ +# C# Section + +All problems are solved in .NET 6, though an effort is made to support other versions. + +## Organization + +All C# files share a common prefix with their problem number. All shared functions are defined in the include folder. + +## Makefile + +There are two main recipes in this Makefile + +### dependencies + +This recipe installs all the required and test dependencies. See the Dependencies section for more info + +### test + +This recipe runs tests in multiple threads + +## Tests + +### Prime Infrastructure Test + +This test checks five things: + +1. It checks `is_prime()` for numbers up to `MAX_PRIME`, where that is defined in the test +2. It checks that `is_composite()` returns truthy values on composites in that range, and falsey values on primes +3. It checks that `is_composite()` returns the smallest prime factor on composite numbers +4. It checks that the prime numbers are generated in the correct order +5. It checks that all these operations are completed in less than 200ns * `MAX_PRIME` + +### Generic Problems + +For each problem it will check the answer against a known dictionary. If the problem is not in the "known slow" category (meaning that I generate the correct answer with a poor solution), it will run it as many times as the benchmark plugin wants. Otherwise it is run exactly once. + +A test fails if it gets the wrong answer or if it takes more than 1 minute. + +## Dependencies + +I try to keep the dependencies of this project as small as possible, except for test plugins. At the moment there are no non-test dependencies for this section. diff --git a/csharp/csharp.csproj b/csharp/csharp.csproj new file mode 100644 index 00000000..50358661 --- /dev/null +++ b/csharp/csharp.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + enable + enable + Linux + . + true + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/csharp/include/primes.cs b/csharp/include/primes.cs new file mode 100644 index 00000000..e69de29b diff --git a/csharp/p0000_template.cs b/csharp/p0000_template.cs new file mode 100644 index 00000000..e69de29b diff --git a/csharp/test.cs b/csharp/test.cs new file mode 100644 index 00000000..e69de29b