Last active
March 27, 2022 13:20
-
-
Save uchan-nos/0c81e794f021ec30327c2750b0a50006 to your computer and use it in GitHub Desktop.
整数を要素とする固定長リングバッファの実装とテストケースのひな形
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
セキュリティ・キャンプ 2022「OS 自作ゼミ」 | |
応募課題 C のひな形ファイル | |
コンパイル&実行方法 | |
$ gcc -Wall -Wextra ring.c | |
$ ./a.out | |
NG: want 2, got 0 | |
NG: want 3, got 0 | |
FAILED: 2/2 tests failed | |
※講師は GCC あるいは Clang で動作を確認します。 | |
最低限、付属の 2 つのテストケースがパスするまで実装してから提出してください。 | |
本コメントブロックを除いたファイル全体を提出してください。 | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
// リングバッファを表す構造体 | |
struct RingBuffer { | |
}; | |
// リングバッファを生成して返す | |
struct RingBuffer *ring_new() { | |
return NULL; | |
} | |
// リングバッファ ring の末尾に要素 value を追加 | |
void ring_push(struct RingBuffer *ring, int value) { | |
} | |
// リングバッファ ring の先頭要素を取り除いて返す | |
int ring_pop(struct RingBuffer *ring) { | |
return 0; | |
} | |
// テスト記述のための便利関数 | |
int fail, success; | |
void assert_equal(int want, int got) { | |
if (want == got) { | |
success++; | |
} else { | |
printf("NG: want %d, got %d\n", want, got); | |
fail++; | |
} | |
} | |
// テストケース群 | |
void test_push_pop() { | |
struct RingBuffer *r = ring_new(); | |
ring_push(r, 2); | |
ring_push(r, 3); | |
assert_equal(2, ring_pop(r)); | |
assert_equal(3, ring_pop(r)); | |
} | |
int main() { | |
test_push_pop(); | |
// 他のテストケース呼び出しはここに追記 | |
if (fail == 0) { | |
printf("PASSED: All tests finished succesfully\n"); | |
} else { | |
printf("FAILED: %d/%d tests failed\n", fail, fail + success); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment