• R/O
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamephpguicwindows翻訳pythonomegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

練習用です。いろんなものがごちゃまぜです。


コミットメタ情報

リビジョン398 (tree)
日時2018-08-03 19:38:41
作者bellyoshi

ログメッセージ

変更サマリ

差分

--- MaxCoins/MaxCoins/CoinsSet.vb (revision 397)
+++ MaxCoins/MaxCoins/CoinsSet.vb (revision 398)
@@ -1,8 +1,14 @@
11 Public Class CoinsSet
22 Public Shared typeMaxNum() As Integer = {4, 1, 4, 1, 4, 1, 1}
33 Public Shared CoinValue() As Integer = {1, 5, 10, 50, 100, 500, 1000}
4- Private CoinNum(CoinValue.Count - 1) As Integer
4+ Private _coinNum(CoinValue.Count - 1) As Integer
55
6+ Public ReadOnly Property CoinNum(ByVal idx As Integer) As Integer
7+ Get
8+ Return _coinNum(idx)
9+ End Get
10+ End Property
11+
612 Public Shared Function TypeCount() As Integer
713 Return CoinValue.Count
814 End Function
@@ -9,15 +15,15 @@
915
1016
1117 Public Sub New(nums As Integer())
12- For i As Integer = 0 To CoinNum.Count - 1
13- Me.CoinNum(i) = nums(i)
18+ For i As Integer = 0 To _coinNum.Count - 1
19+ Me._coinNum(i) = nums(i)
1420 Next
1521 End Sub
1622
1723 Public Function Value() As Integer
1824 Dim v = 0
19- For i As Integer = 0 To CoinNum.Count - 1
20- v += CoinNum(i) * CoinValue(i)
25+ For i As Integer = 0 To _coinNum.Count - 1
26+ v += _coinNum(i) * CoinValue(i)
2127 Next
2228 Return v
2329 End Function
@@ -28,12 +34,12 @@
2834 End Function
2935
3036 Public Function GetClone() As CoinsSet
31- Dim instance As New CoinsSet(Me.CoinNum)
37+ Dim instance As New CoinsSet(Me._coinNum)
3238 Return instance
3339 End Function
3440
3541 Public Function isZero() As Boolean
36- For Each c In Me.CoinNum
42+ For Each c In Me._coinNum
3743 If c <> 0 Then
3844 Return False
3945 End If
@@ -43,10 +49,10 @@
4349
4450 Public Sub dec()
4551 For i As Integer = 0 To typeMaxNum.Count - 1
46- If 0 < Me.CoinNum(i) Then
47- Me.CoinNum(i) -= 1
52+ If 0 < Me._coinNum(i) Then
53+ Me._coinNum(i) -= 1
4854 For j = 0 To i - 1
49- Me.CoinNum(j) = typeMaxNum(j)
55+ Me._coinNum(j) = typeMaxNum(j)
5056 Next
5157 Exit For
5258 End If
@@ -55,10 +61,10 @@
5561
5662 Public Sub DecKeta()
5763 For i As Integer = 0 To typeMaxNum.Count - 1
58- If 0 < Me.CoinNum(i) Then
59- Me.CoinNum(i) = 0
64+ If 0 < Me._coinNum(i) Then
65+ Me._coinNum(i) = 0
6066 For j = 0 To i - 1
61- Me.CoinNum(j) = typeMaxNum(j)
67+ Me._coinNum(j) = typeMaxNum(j)
6268 Next
6369 Exit For
6470 End If
@@ -67,23 +73,26 @@
6773
6874 Public Function subs(ByVal cs As CoinsSet) As CoinsSet
6975 Dim instance = Me.GetClone()
70- For i = 0 To instance.CoinNum.Count - 1
71- instance.CoinNum(i) -= cs.CoinNum(i)
76+ For i = 0 To instance._coinNum.Count - 1
77+ instance._coinNum(i) -= cs._coinNum(i)
7278 Next
7379 Return instance
7480 End Function
7581
7682
77- Public Sub DispUse()
78- For i = 0 To typeMaxNum.Count - 1
79- Console.Write(Me.CoinNum(i))
80- Console.Write(" ")
83+ Public Overrides Function ToString() As String
84+ Dim sb As New Text.StringBuilder
85+ Debug.Assert(0 < Me._coinNum.Count)
86+ sb.Append(Me._coinNum(0))
87+ For i = 1 To typeMaxNum.Count - 1
88+ sb.Append(",")
89+ sb.Append(Me._coinNum(i))
8190 Next
82- Console.WriteLine()
83- End Sub
91+ Return sb.ToString
92+ End Function
8493
8594 Public Function CoinSumNum() As Integer
86- Return CoinNum.Sum()
95+ Return _coinNum.Sum()
8796 End Function
8897
8998 End Class
--- MaxCoins/MaxCoins/MoneyChangePair.vb (revision 397)
+++ MaxCoins/MaxCoins/MoneyChangePair.vb (revision 398)
@@ -14,4 +14,7 @@
1414 Return money.CoinSumNum + change.CoinSumNum
1515 End Function
1616
17+ Public Overrides Function ToString() As String
18+ Return $"{money},{change}"
19+ End Function
1720 End Class
--- MaxCoins/UnitTestProject1/CoinsSetTest.vb (revision 397)
+++ MaxCoins/UnitTestProject1/CoinsSetTest.vb (revision 398)
@@ -8,4 +8,75 @@
88 Assert.AreEqual(CoinsSet.TypeCount, 7)
99 End Sub
1010
11+ <TestMethod()> Public Sub CoinsSumNum()
12+ Dim cs1 = CoinsSet.GetMaxCoins()
13+ Assert.AreEqual(16, cs1.CoinSumNum)
14+ Dim cs2 = New CoinsSet({1, 1, 1, 1, 0, 1, 1})
15+ Assert.AreEqual(6, cs2.CoinSumNum)
16+ End Sub
17+
18+ <TestMethod()> Public Sub CloneTest()
19+ Dim cs1 As New CoinsSet({1, 1, 2, 1, 3, 1, 1})
20+ Dim cs2 = cs1.GetClone()
21+ Assert.AreEqual(True, CoinSetEqual(cs1, cs2))
22+ cs1.dec()
23+ Assert.AreEqual(False, CoinSetEqual(cs1, cs2))
24+ Assert.AreEqual(0, cs1.CoinNum(0))
25+ Assert.AreEqual(1, cs2.CoinNum(0))
26+ End Sub
27+
28+ <TestMethod()> Public Sub decTest()
29+ Dim cs1 = CoinsSet.GetMaxCoins()
30+ Assert.AreEqual(4, cs1.CoinNum(0))
31+ Assert.AreEqual(1, cs1.CoinNum(1))
32+ cs1.dec()
33+ Assert.AreEqual(3, cs1.CoinNum(0))
34+ Assert.AreEqual(1, cs1.CoinNum(1))
35+ cs1.dec()
36+ Assert.AreEqual(2, cs1.CoinNum(0))
37+ cs1.dec()
38+ Assert.AreEqual(1, cs1.CoinNum(0))
39+ cs1.dec()
40+ Assert.AreEqual(0, cs1.CoinNum(0))
41+ cs1.dec()
42+ Assert.AreEqual(4, cs1.CoinNum(0))
43+ Assert.AreEqual(0, cs1.CoinNum(1))
44+
45+ End Sub
46+
47+ <TestMethod()> Public Sub ValueTest()
48+ Dim cs1 = CoinsSet.GetMaxCoins()
49+ Assert.AreEqual(1999, cs1.Value)
50+ cs1.DecKeta()
51+ cs1.DecKeta()
52+ Assert.AreEqual(1994, cs1.Value)
53+ End Sub
54+
55+ <TestMethod()> Public Sub subsTest()
56+ Dim cs1 = CoinsSet.GetMaxCoins()
57+ Dim cs2 = CoinsSet.GetMaxCoins()
58+ Dim cs3 = cs1.subs(cs1)
59+ Assert.AreEqual(True, cs3.isZero())
60+ cs2.dec()
61+ Dim cs4 = cs1.subs(cs2)
62+ Assert.AreEqual(1, cs4.Value)
63+ cs2.DecKeta()
64+ cs2.DecKeta()
65+ Assert.AreEqual(1999, cs1.Value)
66+ Assert.AreEqual(1994, cs2.Value)
67+ Dim cs5 = cs1.subs(cs2)
68+ Assert.AreEqual(5, cs5.Value)
69+ Assert.AreEqual(1999, cs1.Value)
70+ Assert.AreEqual(1994, cs2.Value)
71+ End Sub
72+
73+ Public Function CoinSetEqual(cs1 As CoinsSet, cs2 As CoinsSet)
74+ For i = 0 To CoinsSet.TypeCount - 1
75+ If cs1.CoinNum(i) <> cs2.CoinNum(i) Then
76+ Return False
77+ End If
78+ Next
79+ Return True
80+ End Function
81+
1182 End Class
\ No newline at end of file