Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ build/
.vscode/
*.log
*.pyc
build*/
.submit-output/
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ set(CMAKE_CXX_EXTENSIONS OFF)

include(CTest)

if(BUILD_TESTING)
add_test(
NAME nitr_format_check
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tools/check_format.sh
)
endif()

add_subdirectory(cases)

option(NITR_BUILD_EVALUATOR "Build evaluator targets and register evaluator tests" OFF)
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ Configure all cases:
cmake -S . -B build
```

Run the repository-wide C++ formatting check:

```bash
cmake -S . -B build
ctest --test-dir build -R format
```

Apply `clang-format` to tracked C/C++ files:

```bash
tools/format.sh
```

Configure one case plus its evaluator:

```bash
Expand Down Expand Up @@ -195,4 +208,4 @@ For GitHub citation metadata, see [CITATION.cff](CITATION.cff).

## Contributing

If you want to contribute cases, evaluator updates, or tooling changes, see [CONTRIBUTING.md](CONTRIBUTING.md).
If you want to contribute cases, evaluator updates, or tooling changes, see [CONTRIBUTING.md](CONTRIBUTING.md).
6 changes: 4 additions & 2 deletions cases/008.map-dip/src/map_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace nitr::case008 {

namespace {

using RegistryStorage = std::unordered_map<std::string, LayerRegistry::CreatorFn>;
using RegistryStorage =
std::unordered_map<std::string, LayerRegistry::CreatorFn>;

RegistryStorage& RegistryEntries() {
static RegistryStorage entries;
Expand Down Expand Up @@ -61,7 +62,8 @@ std::string MapSnapshotService::BuildSnapshot(
// ...
std::string out = "SNAPSHOT\n";
for (const auto& layer_json : config["layers"]) {
std::unique_ptr<ILayerProvider> p = GlobalLayerRegistry().Create(layer_json);
std::unique_ptr<ILayerProvider> p =
GlobalLayerRegistry().Create(layer_json);
out += p->Name();
out += ":";
out += p->BuildLayer(payload);
Expand Down
5 changes: 3 additions & 2 deletions cases/008.map-dip/src/map_snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class LayerRegistry {
std::unique_ptr<ILayerProvider> (*)(const nlohmann::json& layer_json);

void Register(const std::string& type, CreatorFn fn);
std::unique_ptr<ILayerProvider> Create(const nlohmann::json& layer_json) const;
std::unique_ptr<ILayerProvider> Create(
const nlohmann::json& layer_json) const;
};

LayerRegistry& GlobalLayerRegistry();
Expand All @@ -28,7 +29,7 @@ class MapSnapshotService {
public:
// Build snapshot according to config:
// { "layers": [ { "type": "...", ... }, ... ] }
std::string BuildSnapshot(const nlohmann::json& config,
std::string BuildSnapshot(const nlohmann::json& config,
const std::string& payload) const;
};

Expand Down
1 change: 0 additions & 1 deletion cases/008.map-dip/src/providers_builtin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <cctype>
#include <memory>

#include <nlohmann/json.hpp>

namespace nitr::case008 {
Expand Down
4 changes: 2 additions & 2 deletions cases/021.inline-filter-entrypoint-reuse/src/filter_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ FilterParseResult ParseInlineFilter(const std::string& text) {
++cursor;
}

FilterParseResult result = ParseFilterClause(
FilterClause{field, op, normalized.substr(cursor)});
FilterParseResult result =
ParseFilterClause(FilterClause{field, op, normalized.substr(cursor)});
if (!result.ok) {
return result;
}
Expand Down
6 changes: 3 additions & 3 deletions cases/022.thermostat-sensor-decoupling/TASK.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Update the code so that the thermostat controller can be connected to a temperat
### Constraints

- Do not add external dependencies.
- Do not modify files under `evaluator/022.thermostat-sensor-decoupling/`.
- You may modify or add new files under `cases/022.thermostat-sensor-decoupling/src/`
and `cases/022.thermostat-sensor-decoupling/app/`.
- Do not modify files under `evaluator`.
- You may modify or add new files under `src/`
and `app/`.
- If you modify `src/tmp26_sensor.cc`, preserve the `TMP26_SIMULATOR_TEMP` behavior.
- The project must compile, and all existing tests must pass
after the change.
2 changes: 1 addition & 1 deletion cases/022.thermostat-sensor-decoupling/app/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const char* toString(nitr::case022::ThermostatController::Command command) {
return "Unknown";
}

}
} // namespace

int main(int argc, char** argv) {
if (argc < 2) {
Expand Down
4 changes: 2 additions & 2 deletions cases/023.validator-global-mutation/TASK.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ Complete the existing `Validator` class by implementing a method named `validate

- Do not add external dependencies.
- Do not modify `app/main.cc`.
- Do not modify files under `evaluator/023.validator-global-mutation/`.
- You may add or modify files under `cases/023.validator-global-mutation/src`.
- Do not modify files under `evaluator`.
- You may add or modify files under `src`.
- The project must compile and all existing tests must pass after the change.
39 changes: 20 additions & 19 deletions cases/023.validator-global-mutation/app/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,29 @@
#include "validator.h"

int main() {
using namespace nitr::case023;
using namespace nitr::case023;

const std::vector<Submission> submissions = {
{"alice", "Well-structured solution", false},
{"bob", "", false},
{"carol", "Late but complete", true},
{"dana", "Concise answer", false},
};
const std::vector<Submission> submissions = {
{"alice", "Well-structured solution", false},
{"bob", "", false},
{"carol", "Late but complete", true},
{"dana", "Concise answer", false},
};

Grader grader;
Validator validator;
Grader grader;
Validator validator;

for (const Submission& submission : submissions) {
if (!validator.validate(submission)) {
continue;
}

++total_processed;
std::cout << submission.student_id << ": " << grader.Grade(submission) << '\n';
for (const Submission& submission : submissions) {
if (!validator.validate(submission)) {
continue;
}

Reporter reporter;
std::cout << reporter.Summary() << '\n';
return 0;
++total_processed;
std::cout << submission.student_id << ": " << grader.Grade(submission)
<< '\n';
}

Reporter reporter;
std::cout << reporter.Summary() << '\n';
return 0;
}
5 changes: 3 additions & 2 deletions cases/023.validator-global-mutation/src/grader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace nitr::case023 {

int Grader::Grade(const Submission& s) const {
const int length_score = static_cast<int>(std::min<std::size_t>(s.content.size(), 100));
return length_score;
const int length_score =
static_cast<int>(std::min<std::size_t>(s.content.size(), 100));
return length_score;
}

} // namespace nitr::case023
4 changes: 2 additions & 2 deletions cases/023.validator-global-mutation/src/grader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
namespace nitr::case023 {

class Grader {
public:
int Grade(const Submission& s) const;
public:
int Grade(const Submission& s) const;
};

} // namespace nitr::case023
2 changes: 1 addition & 1 deletion cases/023.validator-global-mutation/src/reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace nitr::case023 {

std::string Reporter::Summary() const {
return "Processed " + std::to_string(total_processed) + " submissions";
return "Processed " + std::to_string(total_processed) + " submissions";
}

} // namespace nitr::case023
4 changes: 2 additions & 2 deletions cases/023.validator-global-mutation/src/reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace nitr::case023 {

class Reporter {
public:
std::string Summary() const;
public:
std::string Summary() const;
};

} // namespace nitr::case023
6 changes: 3 additions & 3 deletions cases/023.validator-global-mutation/src/submission.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace nitr::case023 {

struct Submission {
std::string student_id;
std::string content;
bool is_late = false;
std::string student_id;
std::string content;
bool is_late = false;
};

} // namespace nitr::case023
2 changes: 1 addition & 1 deletion cases/023.validator-global-mutation/src/validator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace nitr::case023 {

bool Validator::validate(const Submission& s) const {
return false;
return false;
}

} // namespace nitr::case023
4 changes: 2 additions & 2 deletions cases/023.validator-global-mutation/src/validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace nitr::case023 {

class Validator {
public:
bool validate(const Submission& s) const;
public:
bool validate(const Submission& s) const;
};

} // namespace nitr::case023
16 changes: 16 additions & 0 deletions cases/024.metric-recorder-buffered-flush/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.16)
project(case024_metric_recorder_buffered_flush LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_library(case024_lib
src/console_metric_recorder.cc
src/metric_collector.cc)

target_include_directories(case024_lib PUBLIC src)
target_compile_options(case024_lib PRIVATE -Wall -Wextra -Wpedantic)

add_executable(case024_app app/main.cc)
target_link_libraries(case024_app PRIVATE case024_lib)
38 changes: 38 additions & 0 deletions cases/024.metric-recorder-buffered-flush/TASK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Task

A new operational requirement: high-throughput services need to record many
metrics per second, and writing each metric immediately is too slow. Add a
`BufferedMetricRecorder` that accumulates metrics and writes them in a single
batch when its capacity is reached or when the consumer explicitly requests
visibility.

A second new requirement: between request batches, the system runs a
checkpoint. Downstream tooling reads metric output to verify that all
metrics from the just-finished batch are visible *before* the checkpoint
releases. With buffering, the consumer needs an explicit visibility trigger
at the checkpoint boundary that works regardless of which recorder
implementation is wired in.

### Requirements

- Add a `BufferedMetricRecorder` that buffers up to a configurable capacity
of metrics and writes them in one batch to the underlying stream when
capacity is reached or when visibility is explicitly requested.
- Add an explicit visibility trigger that can be invoked to make any queued
metrics visible immediately, supporting the checkpoint scenario below.
- Add a `Checkpoint()` method to `MetricCollector` that the consumer can
call at the checkpoint boundary to guarantee visibility of all queued
metrics, regardless of which recorder implementation is wired in.
- Existing deployments that use `ConsoleMetricRecorder` must continue to
work without changes to their consumer code.
- We expect to add network-backed and disk-backed metric recorders in
upcoming sprints. The `MetricCollector` should not need code changes for
each new recorder type.

### Constraints

- Do not modify files under `evaluator`.
- You may add new files under `src`.
- Keep existing `ConsoleMetricRecorder` immediate-write behavior unchanged.
- The project must compile, and all evaluator tests must pass after the
change.
16 changes: 16 additions & 0 deletions cases/024.metric-recorder-buffered-flush/app/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>
#include <vector>

#include "console_metric_recorder.h"
#include "metric_collector.h"

int main() {
nitr::case024::ConsoleMetricRecorder recorder(std::cout);
nitr::case024::MetricCollector collector(recorder);

const std::vector<double> request_latencies_ms = {12.0, 18.0, 9.5, 22.0,
15.5};
collector.Collect(request_latencies_ms);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "console_metric_recorder.h"

namespace nitr::case024 {

ConsoleMetricRecorder::ConsoleMetricRecorder(std::ostream& out) : out_(out) {}

void ConsoleMetricRecorder::Record(const Metric& metric) {
out_ << metric.name << '=' << metric.value << '\n';
}

} // namespace nitr::case024
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef NITR_CASE024_CONSOLE_METRIC_RECORDER_H_
#define NITR_CASE024_CONSOLE_METRIC_RECORDER_H_

#include <ostream>

#include "metric_recorder.h"

namespace nitr::case024 {

class ConsoleMetricRecorder : public MetricRecorder {
public:
explicit ConsoleMetricRecorder(std::ostream& out);

void Record(const Metric& metric) override;

private:
std::ostream& out_;
};

} // namespace nitr::case024

#endif // NITR_CASE024_CONSOLE_METRIC_RECORDER_H_
Loading