Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programming exercises: Add C++ programming language template #9261

Merged
merged 33 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
337e809
Add C++ programming language template as copy of C template
magaupp Sep 20, 2024
4c8f698
Move test repository checkout to `.`
magaupp Sep 20, 2024
fcb43ff
Add changes to C++ template
magaupp Sep 20, 2024
44ca5e8
Add GitLab CI support
magaupp Sep 20, 2024
1c44ee2
Add plagiarism detection
magaupp Sep 20, 2024
87b7448
Add Python type hints suggested by Ruff
magaupp Oct 4, 2024
5ad816b
Implement additional Roff suggestions
magaupp Oct 5, 2024
95af054
Merge branch 'develop' into feature/programming-exercises/cpp-template
magaupp Oct 5, 2024
811ce10
Fix TestClangFormat comment
magaupp Oct 5, 2024
8244fec
Other small Python improvements
magaupp Oct 5, 2024
068a9c2
More small Python improvements
magaupp Oct 5, 2024
7fb1236
Handle empty files with clang-format
magaupp Oct 5, 2024
5e1b8fd
Fix typos
magaupp Oct 5, 2024
26b5f39
Add test docker image
magaupp Oct 5, 2024
d0dedd9
Add missing return types
magaupp Oct 5, 2024
374db29
Fix more typos
magaupp Oct 5, 2024
8f45722
Sort lists of programming languages
magaupp Oct 6, 2024
4f7c7b9
Merge branch 'develop' into feature/programming-exercises/cpp-template
magaupp Oct 6, 2024
f44759b
Remove duplicate Java jplag dependency
magaupp Oct 6, 2024
952c2fa
Remove clang-format test
magaupp Oct 8, 2024
813b6a6
Add task description
magaupp Oct 8, 2024
fa5c351
Remove GitLab CI support
magaupp Oct 8, 2024
c6b24d1
Merge branch 'develop' into feature/programming-exercises/cpp-template
magaupp Oct 8, 2024
48111d1
Fix readme typo
magaupp Oct 11, 2024
83bb788
Merge branch 'develop' into feature/programming-exercises/cpp-template
magaupp Oct 11, 2024
13ea523
Explain deterministic Bogosort
magaupp Oct 12, 2024
5af056f
Merge branch 'develop' into feature/programming-exercises/cpp-template
magaupp Oct 12, 2024
4341e21
Merge branch 'develop' into feature/programming-exercises/cpp-template
magaupp Oct 12, 2024
9112d80
Fix Jenkins Build
magaupp Oct 12, 2024
0c36fed
Merge branch 'develop' into feature/programming-exercises/cpp-template
magaupp Oct 12, 2024
3886c42
Merge branch 'develop' into feature/programming-exercises/cpp-template
magaupp Oct 12, 2024
9ed8fcd
Add checkout path replacement variables
magaupp Oct 13, 2024
60b6e39
Pin Catch2 version
magaupp Oct 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ dependencies {
implementation "de.jplag:swift:${jplag_version}"
implementation "de.jplag:java:${jplag_version}"
implementation "de.jplag:python-3:${jplag_version}"
implementation "de.jplag:cpp:${jplag_version}"
implementation "de.jplag:text:${jplag_version}"

// those are transitive dependencies of JPlag Text --> Stanford NLP
Expand Down
4 changes: 4 additions & 0 deletions docs/user/exercises/programming-exercise-features.inc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Instructors can still use those templates to generate programming exercises and
+----------------------+----------+---------+
| JavaScript | yes | yes |
+----------------------+----------+---------+
| C++ | yes | yes |
+----------------------+----------+---------+
magaupp marked this conversation as resolved.
Show resolved Hide resolved

- Not all ``templates`` support the same feature set and supported features can also change depending on the continuous integration system setup.
Depending on the feature set, some options might not be available during the creation of the programming exercise.
Expand Down Expand Up @@ -71,6 +73,8 @@ Instructors can still use those templates to generate programming exercises and
+----------------------+----------------------+----------------------+---------------------+--------------+------------------------------------------+------------------------------+----------------------------+------------------------+
| JavaScript | no | no | no | no | n/a | no | no | L: yes, J: no |
+----------------------+----------------------+----------------------+---------------------+--------------+------------------------------------------+------------------------------+----------------------------+------------------------+
| C++ | no | no | yes | no | n/a | no | no | L: yes, J: no |
+----------------------+----------------------+----------------------+---------------------+--------------+------------------------------------------+------------------------------+----------------------------+------------------------+
magaupp marked this conversation as resolved.
Show resolved Hide resolved

- *Sequential Test Runs*: ``Artemis`` can generate a build plan which first executes structural and then behavioral tests. This feature can help students to better concentrate on the immediate challenge at hand.
- *Static Code Analysis*: ``Artemis`` can generate a build plan which additionally executes static code analysis tools.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import de.jplag.Language;
import de.jplag.c.CLanguage;
import de.jplag.clustering.ClusteringOptions;
import de.jplag.cpp.CPPLanguage;
import de.jplag.exceptions.ExitException;
import de.jplag.java.JavaLanguage;
import de.jplag.kotlin.KotlinLanguage;
Expand Down Expand Up @@ -313,6 +314,7 @@ private Language getJPlagProgrammingLanguage(ProgrammingExercise programmingExer
case PYTHON -> new PythonLanguage();
case SWIFT -> new SwiftLanguage();
case KOTLIN -> new KotlinLanguage();
case C_PLUS_PLUS -> new CPPLanguage();
default -> throw new BadRequestAlertException("Programming language " + programmingExercise.getProgrammingLanguage() + " not supported for plagiarism check.",
"ProgrammingExercise", "notSupported");
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public enum ProgrammingLanguage {
PHP("php");

private static final Set<ProgrammingLanguage> ENABLED_LANGUAGES = Set.of(
EMPTY,
JAVA,
PYTHON,
C,
Expand All @@ -49,7 +48,9 @@ public enum ProgrammingLanguage {
SWIFT,
OCAML,
RUST,
JAVASCRIPT
JAVASCRIPT,
C_PLUS_PLUS,
EMPTY
);
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public TemplateUpgradePolicyService(JavaTemplateUpgradeService javaRepositoryUpg
public TemplateUpgradeService getUpgradeService(ProgrammingLanguage programmingLanguage) {
return switch (programmingLanguage) {
case JAVA -> javaRepositoryUpgradeService;
case KOTLIN, PYTHON, C, HASKELL, VHDL, ASSEMBLER, SWIFT, OCAML, EMPTY, RUST, JAVASCRIPT -> defaultRepositoryUpgradeService;
case C_SHARP, C_PLUS_PLUS, SQL, R, TYPESCRIPT, GO, MATLAB, BASH, RUBY, POWERSHELL, ADA, DART, PHP ->
case KOTLIN, PYTHON, C, HASKELL, VHDL, ASSEMBLER, SWIFT, OCAML, EMPTY, RUST, JAVASCRIPT, C_PLUS_PLUS -> defaultRepositoryUpgradeService;
case C_SHARP, SQL, R, TYPESCRIPT, GO, MATLAB, BASH, RUBY, POWERSHELL, ADA, DART, PHP ->
throw new UnsupportedOperationException("Unsupported programming language: " + programmingLanguage);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ enum RepositoryCheckoutPath implements CustomizableCheckoutPath {
@Override
public String forProgrammingLanguage(ProgrammingLanguage language) {
return switch (language) {
case JAVA, PYTHON, C, HASKELL, KOTLIN, VHDL, ASSEMBLER, SWIFT, OCAML, EMPTY, RUST, JAVASCRIPT -> "assignment";
case C_SHARP, C_PLUS_PLUS, SQL, R, TYPESCRIPT, GO, MATLAB, BASH, RUBY, POWERSHELL, ADA, DART, PHP ->
case JAVA, PYTHON, C, HASKELL, KOTLIN, VHDL, ASSEMBLER, SWIFT, OCAML, EMPTY, RUST, JAVASCRIPT, C_PLUS_PLUS -> "assignment";
case C_SHARP, SQL, R, TYPESCRIPT, GO, MATLAB, BASH, RUBY, POWERSHELL, ADA, DART, PHP ->
throw new UnsupportedOperationException("Unsupported programming language: " + language);
};
}
Expand All @@ -230,9 +230,9 @@ public String forProgrammingLanguage(ProgrammingLanguage language) {
@Override
public String forProgrammingLanguage(ProgrammingLanguage language) {
return switch (language) {
case JAVA, PYTHON, HASKELL, KOTLIN, SWIFT, EMPTY, RUST, JAVASCRIPT -> "";
case JAVA, PYTHON, HASKELL, KOTLIN, SWIFT, EMPTY, RUST, JAVASCRIPT, C_PLUS_PLUS -> "";
case C, VHDL, ASSEMBLER, OCAML -> "tests";
case C_SHARP, C_PLUS_PLUS, SQL, R, TYPESCRIPT, GO, MATLAB, BASH, RUBY, POWERSHELL, ADA, DART, PHP ->
case C_SHARP, SQL, R, TYPESCRIPT, GO, MATLAB, BASH, RUBY, POWERSHELL, ADA, DART, PHP ->
throw new UnsupportedOperationException("Unsupported programming language: " + language);
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.tum.cit.aet.artemis.programming.service.gitlabci;

import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.C_PLUS_PLUS;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.EMPTY;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.JAVA;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.JAVASCRIPT;
Expand Down Expand Up @@ -27,5 +28,6 @@ public GitLabCIProgrammingLanguageFeatureService() {
programmingLanguageFeatures.put(JAVA, new ProgrammingLanguageFeature(JAVA, false, false, false, true, false, List.of(PLAIN_MAVEN, MAVEN_MAVEN), false, false));
programmingLanguageFeatures.put(RUST, new ProgrammingLanguageFeature(RUST, false, false, false, false, false, List.of(), false, false));
programmingLanguageFeatures.put(JAVASCRIPT, new ProgrammingLanguageFeature(JAVASCRIPT, false, false, false, false, false, List.of(), false, false));
programmingLanguageFeatures.put(C_PLUS_PLUS, new ProgrammingLanguageFeature(C_PLUS_PLUS, false, false, true, false, false, List.of(), false, false));
magaupp marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.tum.cit.aet.artemis.programming.service.jenkins;

import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.C;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.C_PLUS_PLUS;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.EMPTY;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.HASKELL;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.JAVA;
Expand Down Expand Up @@ -43,5 +44,6 @@ public JenkinsProgrammingLanguageFeatureService() {
programmingLanguageFeatures.put(HASKELL, new ProgrammingLanguageFeature(HASKELL, false, false, false, false, true, List.of(), false, false));
programmingLanguageFeatures.put(RUST, new ProgrammingLanguageFeature(RUST, false, false, false, false, false, List.of(), false, false));
programmingLanguageFeatures.put(JAVASCRIPT, new ProgrammingLanguageFeature(JAVASCRIPT, false, false, false, false, false, List.of(), false, false));
programmingLanguageFeatures.put(C_PLUS_PLUS, new ProgrammingLanguageFeature(C_PLUS_PLUS, false, false, true, false, false, List.of(), false, false));
magaupp marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ private JenkinsXmlConfigBuilder builderFor(ProgrammingLanguage programmingLangua
throw new UnsupportedOperationException("Xcode templates are not available for Jenkins.");
}
return switch (programmingLanguage) {
case JAVA, KOTLIN, PYTHON, C, HASKELL, SWIFT, EMPTY, RUST, JAVASCRIPT -> jenkinsBuildPlanCreator;
case VHDL, ASSEMBLER, OCAML, C_SHARP, C_PLUS_PLUS, SQL, R, TYPESCRIPT, GO, MATLAB, BASH, RUBY, POWERSHELL, ADA, DART, PHP ->
case JAVA, KOTLIN, PYTHON, C, HASKELL, SWIFT, EMPTY, RUST, JAVASCRIPT, C_PLUS_PLUS -> jenkinsBuildPlanCreator;
case VHDL, ASSEMBLER, OCAML, C_SHARP, SQL, R, TYPESCRIPT, GO, MATLAB, BASH, RUBY, POWERSHELL, ADA, DART, PHP ->
throw new UnsupportedOperationException(programmingLanguage + " templates are not available for Jenkins.");
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_LOCALCI;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.ASSEMBLER;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.C;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.C_PLUS_PLUS;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.EMPTY;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.HASKELL;
import static de.tum.cit.aet.artemis.programming.domain.ProgrammingLanguage.JAVA;
Expand Down Expand Up @@ -51,5 +52,6 @@ public LocalCIProgrammingLanguageFeatureService() {
programmingLanguageFeatures.put(SWIFT, new ProgrammingLanguageFeature(SWIFT, false, false, true, true, false, List.of(PLAIN), false, true));
programmingLanguageFeatures.put(RUST, new ProgrammingLanguageFeature(RUST, false, false, false, false, false, List.of(), false, true));
programmingLanguageFeatures.put(JAVASCRIPT, new ProgrammingLanguageFeature(JAVASCRIPT, false, false, false, false, false, List.of(), false, true));
programmingLanguageFeatures.put(C_PLUS_PLUS, new ProgrammingLanguageFeature(C_PLUS_PLUS, false, false, true, false, false, List.of(), false, true));
magaupp marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 2 additions & 0 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ artemis:
default: "ghcr.io/ls1intum/artemis-rust-docker:v0.9.70"
javascript:
default: "ghcr.io/ls1intum/artemis-javascript-docker:v1.0.0"
c_plus_plus:
default: "ghcr.io/ls1intum/artemis-cpp-docker:v1.0.0"

management:
endpoints:
Expand Down
56 changes: 56 additions & 0 deletions src/main/resources/templates/aeolus/c_plus_plus/default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
set -e
export AEOLUS_INITIAL_DIRECTORY=${PWD}
setup_the_build_environment () {
echo '⚙️ executing setup_the_build_environment'
#!/usr/bin/env bash

# ------------------------------
# Task Description:
# Setup the build environment
# ------------------------------

mkdir test-reports

# Updating ownership...
chown -R artemis_user:artemis_user .

REQ_FILE=requirements.txt
if [ -f "$REQ_FILE" ]; then
python3 -m venv /venv
/venv/bin/pip3 install -r "$REQ_FILE"
else
echo "$REQ_FILE does not exist"
fi
}

build_and_run_all_tests () {
echo '⚙️ executing build_and_run_all_tests'
#!/usr/bin/env bash

# ------------------------------
# Task Description:
# Build and run all tests
# ------------------------------

if [ -d /venv ]; then
. /venv/bin/activate
fi

# Run tests as unprivileged user
runuser -u artemis_user python3 Tests.py
}
magaupp marked this conversation as resolved.
Show resolved Hide resolved

main () {
if [[ "${1}" == "aeolus_sourcing" ]]; then
return 0 # just source to use the methods in the subshell, no execution
fi
local _script_name
_script_name=${BASH_SOURCE[0]:-$0}
cd "${AEOLUS_INITIAL_DIRECTORY}"
bash -c "source ${_script_name} aeolus_sourcing; setup_the_build_environment"
cd "${AEOLUS_INITIAL_DIRECTORY}"
bash -c "source ${_script_name} aeolus_sourcing; build_and_run_all_tests"
}

main "${@}"
48 changes: 48 additions & 0 deletions src/main/resources/templates/aeolus/c_plus_plus/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
api: v0.0.1
metadata:
name: C++
id: c_plus_plus
description: Test using the GBS Tester
actions:
- name: setup_the_build_environment
script: |-
#!/usr/bin/env bash

# ------------------------------
# Task Description:
# Setup the build environment
# ------------------------------

mkdir test-reports

# Updating ownership...
chown -R artemis_user:artemis_user .

REQ_FILE=requirements.txt
if [ -f "$REQ_FILE" ]; then
python3 -m venv /venv
/venv/bin/pip3 install -r "$REQ_FILE"
else
echo "$REQ_FILE does not exist"
fi
runAlways: false
- name: build_and_run_all_tests
script: |-
#!/usr/bin/env bash

# ------------------------------
# Task Description:
# Build and run all tests
# ------------------------------

if [ -d /venv ]; then
. /venv/bin/activate
fi

# Run tests as unprivileged user
runuser -u artemis_user python3 Tests.py
runAlways: false
results:
- name: junit_test-reports/tests-results.xml
path: 'test-reports/*.xml'
type: junit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
Language: Cpp
BasedOnStyle: Google
IncludeBlocks: Preserve
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Source: https://github.com/gitattributes/gitattributes/blob/master/C%2B%2B.gitattributes (01.09.2024)

# Sources
*.c text diff=cpp
*.cc text diff=cpp
*.cxx text diff=cpp
*.cpp text diff=cpp
*.cpi text diff=cpp
*.c++ text diff=cpp
*.hpp text diff=cpp
*.h text diff=cpp
*.h++ text diff=cpp
*.hh text diff=cpp

# Compiled Object files
*.slo binary
*.lo binary
*.o binary
*.obj binary

# Precompiled Headers
*.gch binary
*.pch binary

# Compiled Dynamic libraries
*.so binary
*.dylib binary
*.dll binary

# Compiled Static libraries
*.lai binary
*.la binary
*.a binary
*.lib binary

# Executables
*.exe binary
*.out binary
*.app binary
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake-build-*/

.vscode/
.idea/
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.13)
project(ArtemisExercise)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_library(assignment src/sort.cpp)
target_include_directories(assignment PUBLIC include)

add_executable(assignment_main src/main.cpp)
target_link_libraries(assignment_main assignment)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <vector>

void selection_sort(std::vector<int>::iterator begin,
std::vector<int>::iterator end);

void insertion_sort(std::vector<int>::iterator begin,
std::vector<int>::iterator end);

void quicksort(std::vector<int>::iterator begin,
std::vector<int>::iterator end);

void mergesort(std::vector<int>::iterator begin,
std::vector<int>::iterator end);

void mergesort_inplace(std::vector<int>::iterator begin,
std::vector<int>::iterator end);

void heapsort(std::vector<int>::iterator begin, std::vector<int>::iterator end);

void heapsort_explicit(std::vector<int>::iterator begin,
std::vector<int>::iterator end);

void bogosort(std::vector<int>::iterator begin, std::vector<int>::iterator end);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "sort.hpp"

int main() {
// Test your implementation here
}
magaupp marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading