Skip to content

Commit

Permalink
Begin csharp port
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Jun 25, 2024
1 parent d61d4e6 commit 3deb140
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 2 deletions.
30 changes: 29 additions & 1 deletion .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ jobs:

c:
strategy:
fail-fast: false
matrix:
# compiler: ["llvm", "gcc"]
# # compiler targets (ideally): clang, gcc, MSVCC, pcc, tcc, icc,
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 10 additions & 0 deletions csharp/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test: dependencies
dotnet test

test_%: dependencies
echo "WARNING: multithreaded tests not supported on javascript"
$(MAKE) test

dependencies:
dotnet restore

41 changes: 41 additions & 0 deletions csharp/README.md
Original file line number Diff line number Diff line change
@@ -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.
27 changes: 27 additions & 0 deletions csharp/csharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>.</DockerfileContext>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.8.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.21" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.21">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.21">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
Empty file added csharp/include/primes.cs
Empty file.
Empty file added csharp/p0000_template.cs
Empty file.
Empty file added csharp/test.cs
Empty file.

0 comments on commit 3deb140

Please sign in to comment.