-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from niuez/v0.7
v0.7
- Loading branch information
Showing
34 changed files
with
1,012 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# ユニットテスト | ||
|
||
Niu言語のユニットテストでは, [library-checker-problems](https://github.com/yosupo06/library-checker-problems)で使われている問題を使うことができます. | ||
|
||
## library.toml | ||
|
||
`library.toml`にテストをするための設定を書いておきます. 以下は一例です. | ||
|
||
```toml | ||
compiler="g++" | ||
compile_options=["-std=c++17"] | ||
|
||
[[testers]] | ||
name="library-checker-problems" | ||
repo="https://github.com/yosupo06/library-checker-problems" | ||
generator="generate.py" | ||
``` | ||
|
||
- `compiler`: コンパイラの指定 | ||
- `compile_options`: コンパイラに渡すオプション | ||
- testers | ||
- `name`: テストに使う問題集の名前 | ||
- `repo`: 問題があるリポジトリのurl | ||
- `generator`: 入出力を生成するために使うスクリプトの指定 | ||
|
||
## ユニットテストの書きかた | ||
|
||
`aplusb`を例に書いてみます. | ||
|
||
``` | ||
import "std/u64.niu" | ||
fn aplusb(a: u64, b: u64) -> u64 { | ||
a + b | ||
} | ||
testfn(library-checker-problems:sample/aplusb) aplusb_test $${ | ||
long long a, b; | ||
std::cin >> a >> b; | ||
std::cout << aplusb(a, b) << "\n"; | ||
}$$ | ||
``` | ||
|
||
`testfn([テストの名前(name)]:[問題のディレクトリ]) [テスト名] $${ [C++のコード] }$$` C++のコードの内容が`int main()`に展開され, テストされます. | ||
|
||
## テストの実行 | ||
|
||
`niu test` | ||
|
||
`transpile/`にトランスパイルしたコードが出力され, `.test/`にテストに必要なコードが出力されます. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() -> void { | ||
let a = 5; | ||
let b = &&a; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import "std/opes.niu" | ||
|
||
impl Eq for u64 { | ||
fn eq(self: &Self, right: &Self) -> bool $${self == right}$$ | ||
} | ||
|
||
struct Hoge<T> { | ||
v: T, | ||
} {} | ||
|
||
impl<T> Eq for Hoge<T> where T: Eq { | ||
fn eq(self: &Self, right: &Self) -> bool { | ||
self.v == right.v | ||
} | ||
} | ||
|
||
fn main() -> void { | ||
let a = Hoge { v: 3 }; | ||
let b = Hoge { v: 4 }; | ||
let ans = a == b; | ||
let ans2 = a != b; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import "std/opes.niu" | ||
import "std/u64.niu" | ||
import "std/vec.niu" | ||
|
||
struct Hoge<T> { | ||
v: T, | ||
} {} | ||
|
||
impl<T> Eq for Hoge<T> where T: Eq { | ||
fn eq(a: &Self, b: &Self) -> bool { | ||
a.v == b.v | ||
} | ||
} | ||
|
||
impl<T> Ord for Hoge<T> where T: Ord { | ||
fn le(a: &Self, b: &Self) -> bool { | ||
a.v < b.v | ||
} | ||
} | ||
|
||
fn main() -> void { | ||
let a = Hoge { v: 3 }; | ||
let b = Hoge { v: 2 }; | ||
let ans = a < b; | ||
let mut vec = Vec::new(); | ||
vec.push(a); | ||
vec.push(b); | ||
vec.sort(); | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import "segment_tree.niu" | ||
import "math/modint.niu" | ||
|
||
struct Am { | ||
v: i64, | ||
} { | ||
fn init(v: i64) -> Am { | ||
Am { v: v } | ||
} | ||
} | ||
|
||
impl Monoid for Am { | ||
fn ide() -> Am { Am::init(0i64) } | ||
fn ope(self: &Am, right: &Am) -> Am { | ||
Am::init(self.v + right.v) | ||
} | ||
} | ||
|
||
struct Fm { | ||
a: Modint<M9982>, | ||
b: Modint<M9982>, | ||
} { | ||
fn init(a: u64, b: u64) -> Fm { | ||
Fm { a: Modint::init(a), b: Modint::init(b) } | ||
} | ||
} | ||
|
||
impl Monoid for Fm { | ||
fn ide() -> Fm { Fm::init(1u64, 0u64) } | ||
fn ope(a: &Fm, b: &Fm) -> Fm { | ||
Fm { a: a.a * b.a, b: a.b * b.a + b.b } | ||
} | ||
} | ||
|
||
|
||
testfn(library-checker-problems:datastructure/point_add_range_sum) segmenttree_point_add_range_sum $${ | ||
std::cin.tie(nullptr); | ||
int N, Q; | ||
std::cin >> N >> Q; | ||
std::vector<Am> a(N, Am::init(0)); | ||
for(int i = 0; i < N; i++) { | ||
long long v; | ||
std::cin >> v; | ||
a[i] = Am::init(v); | ||
} | ||
using Seg = SegmentTree<Am>; | ||
auto seg = Seg::init(a); | ||
while(Q--) { | ||
int t, a, b; | ||
std::cin >> t >> a >> b; | ||
if(t == 0) { | ||
Seg::update(seg, a, Am::init(Seg::get(seg, a).v + b)); | ||
} | ||
else { | ||
std::cout << Seg::sum(seg, a, b).v << '\n'; | ||
} | ||
} | ||
}$$ | ||
|
||
testfn(library-checker-problems:datastructure/point_set_range_composite) segmenttree_point_set_range_composite $${ | ||
std::cin.tie(nullptr); | ||
int N, Q; | ||
std::cin >> N >> Q; | ||
std::vector<Fm> a(N, Fm::init(1, 0)); | ||
for(int i = 0; i < N; i++) { | ||
long long v, w; | ||
std::cin >> v >> w; | ||
a[i] = Fm::init(v, w); | ||
} | ||
using Seg = SegmentTree<Fm>; | ||
auto seg = Seg::init(a); | ||
while(Q--) { | ||
int t, a, b, c; | ||
std::cin >> t >> a >> b >> c; | ||
if(t == 0) { | ||
Seg::update(seg, a, Fm::init(b, c)); | ||
} | ||
else { | ||
Fm ans = Seg::sum(seg, a, b); | ||
std::cout << (ans.a * Modint<M9982>(c) + ans.b).a << '\n'; | ||
} | ||
} | ||
}$$ | ||
|
||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
compiler="g++" | ||
compile_options=["-std=c++17", "-O2"] | ||
|
||
[[testers]] | ||
name="library-checker-problems" | ||
repo="https://github.com/yosupo06/library-checker-problems" | ||
generator="generate.py" |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
#include <vector> | ||
#include <algorithm> | ||
import "std/opes.niu" | ||
|
||
struct Vec<T> $${std::vector<$ty(T)>}$$ { | ||
fn new() -> Self $${std::vector<$ty(T)>()}$$ | ||
fn init(N: u64, t: T) -> Self $${std::vector<$ty(T)>($arg(N), $arg(t))}$$ | ||
fn push(self: &mut Self, t: T) -> void $${$arg(self)->push_back($arg(t))}$$ | ||
fn len(self: &Self) -> u64 $${$arg(self)->size()}$$ | ||
fn pop(self: &mut Self) -> void $${$arg(self)->pop_back()}$$ | ||
fn push(self: &mut Self, t: T) -> void $${$arg(self).push_back($arg(t))}$$ | ||
fn len(self: &Self) -> u64 $${$arg(self).size()}$$ | ||
fn pop(self: &mut Self) -> void $${$arg(self).pop_back()}$$ | ||
fn sort(self: &mut Self) -> void where T: Ord $${std::sort($arg(self).begin(), $arg(self).end())}$$ | ||
} | ||
|
||
impl<T> Index for Vec<T> { | ||
type Output = T; | ||
type Arg = u64; | ||
fn index(self: &Self, i: u64) -> &T $${(&$arg(self)->at($arg(i)))}$$ | ||
fn index(self: &Self, i: u64) -> &T $${$arg(self).at($arg(i))}$$ | ||
} | ||
|
||
impl<T> IndexMut for Vec<T> { | ||
fn index_mut(self: &mut Self, i: u64) -> &mut T $${(&$arg(self)->at($arg(i)))}$$ | ||
fn index_mut(self: &mut Self, i: u64) -> &mut T $${$arg(self).at($arg(i))}$$ | ||
} | ||
|
||
impl<T> Eq for Vec<T> where T: Eq { | ||
fn eq(self: &Self, right: &Self) -> bool $${self==right}$$ | ||
} |
This file contains 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
Oops, something went wrong.