using NUnit Framework namespace Wankuma Sorter Sample Test
- Slides: 38
最初のテスト (コード) using NUnit. Framework; namespace Wankuma. Sorter. Sample. Test { [Test. Fixture] public class Wankuma. Sorter. Test { [Test] [Description("初めての NUnit テスト")] public void First. Test() { Assert. Fail("ちゃんと Assert できました! (^^; "); } } } ---- src 00. sln ---- • このテストは失敗します ( レッド ) 失敗させようとして、 失敗した → ちゃんと動いている ! わんくま同盟 名古屋勉強会 #3
テストケース : n = 2 ( テストコード ) [Test] [Description("n=2 のとき。 逆順なら入れ替え。")] public void Sort. Test. With 2 Items() { int[] input = { 5, 3 }; Wankuma. Sorter sorter = new Wankuma. Sorter(); int[] result = sorter. Sort(input); Collection. Assert. Are. Equal( new int[] { 3, 5 }, result ); } ※ ちゃんとテストは失敗しますね? これから実装することに意味がある、 というものです わんくま同盟 名古屋勉強会 #3
テストケース : n = 3 ( 製品コード ) そこで、 for 文で書き直すことにします。 public int[] Sort(int[] input) { if (input. Length == 1) return input; for (int i = 0; i < (input. Length - 1); i++) { if (input[i] > input[i+1]) { Swap(ref input[i], ref input[i+1]); } } return input; } わんくま同盟 名古屋勉強会 #3
テストプローブの挿入 (製品コード ) • オールグリーンを確認したら、 プローブ を仕込みます。 #if DEBUG public static int Test. Compare. Count; #endif private static bool Is. Not. In. Order(int lead, int trail ) { #if DEBUG Test. Compare. Count++; #endif return (lead > trail); } わんくま同盟 名古屋勉強会 #3
• そして、 内側のループに入る前に _swap. Count をゼロ クリアして、出てきたときにゼロのままだったら、 ソ ート終了と判定します。 public int[] Sort(int[] input) { if (input. Length == 1) return input; } for (int stop = input. Length - 1; stop > 0; stop--) { this. _swap. Count = 0; for (int i = 0; i < stop; i++) { if (Is. Not. In. Order(input[i], input[i + 1])) { Swap(ref input[i], ref input[i + 1]); } } if ( this. _swap. Count == 0 ) break; } return input; // ---- src 04. sln ---- わんくま同盟 名古屋勉強会 #3
- Marble sorter
- Vinterpotatis sorter
- Linearsorter
- Perceptron sorter
- Willy
- Gene sorter
- Lego sorting robot
- Iostream
- #include iostream #include string using namespace std
- #include iostream using namespace std
- C include iostream
- Iostream
- #include iostream
- Include iostream using namespace std
- Using namespace std int main()
- Template
- Namespace string
- 윤년 순서도
- Fungsi using namespace std
- Using namespace std
- Include iostream using namespace std
- Using namespace std
- Using namespace std c++
- #include iostream using namespace std
- Wankuma
- Lpdispatch
- Wankuma
- Uji z spss
- Dispositional framework vs regulatory framework
- Theoretical framework vs conceptual framework
- Franmework
- Conceptual framework theoretical framework
- Dispositional framework vs regulatory framework
- Theoretical framework
- Python application