bellyoshi

練習用svn

• R/O
• SSH
• HTTPS

コミット

コミットメタ情報

リビジョン 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 @@ 1 1 ﻿Public Class CoinsSet 2 2 Public Shared typeMaxNum() As Integer = {4, 1, 4, 1, 4, 1, 1} 3 3 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 5 5 6 + Public ReadOnly Property CoinNum(ByVal idx As Integer) As Integer 7 + Get 8 + Return _coinNum(idx) 9 + End Get 10 + End Property 11 + 6 12 Public Shared Function TypeCount() As Integer 7 13 Return CoinValue.Count 8 14 End Function
 @@ -9,15 +15,15 @@ 9 15 10 16 11 17 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) 14 20 Next 15 21 End Sub 16 22 17 23 Public Function Value() As Integer 18 24 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) 21 27 Next 22 28 Return v 23 29 End Function
 @@ -28,12 +34,12 @@ 28 34 End Function 29 35 30 36 Public Function GetClone() As CoinsSet 31 - Dim instance As New CoinsSet(Me.CoinNum) 37 + Dim instance As New CoinsSet(Me._coinNum) 32 38 Return instance 33 39 End Function 34 40 35 41 Public Function isZero() As Boolean 36 - For Each c In Me.CoinNum 42 + For Each c In Me._coinNum 37 43 If c <> 0 Then 38 44 Return False 39 45 End If
 @@ -43,10 +49,10 @@ 43 49 44 50 Public Sub dec() 45 51 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 48 54 For j = 0 To i - 1 49 - Me.CoinNum(j) = typeMaxNum(j) 55 + Me._coinNum(j) = typeMaxNum(j) 50 56 Next 51 57 Exit For 52 58 End If
 @@ -55,10 +61,10 @@ 55 61 56 62 Public Sub DecKeta() 57 63 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 60 66 For j = 0 To i - 1 61 - Me.CoinNum(j) = typeMaxNum(j) 67 + Me._coinNum(j) = typeMaxNum(j) 62 68 Next 63 69 Exit For 64 70 End If
 @@ -67,23 +73,26 @@ 67 73 68 74 Public Function subs(ByVal cs As CoinsSet) As CoinsSet 69 75 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) 72 78 Next 73 79 Return instance 74 80 End Function 75 81 76 82 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)) 81 90 Next 82 - Console.WriteLine() 83 - End Sub 91 + Return sb.ToString 92 + End Function 84 93 85 94 Public Function CoinSumNum() As Integer 86 - Return CoinNum.Sum() 95 + Return _coinNum.Sum() 87 96 End Function 88 97 89 98 End Class
--- MaxCoins/MaxCoins/MoneyChangePair.vb (revision 397)
+++ MaxCoins/MaxCoins/MoneyChangePair.vb (revision 398)
 @@ -14,4 +14,7 @@ 14 14 Return money.CoinSumNum + change.CoinSumNum 15 15 End Function 16 16 17 + Public Overrides Function ToString() As String 18 + Return \$"{money},{change}" 19 + End Function 17 20 End Class
--- MaxCoins/UnitTestProject1/CoinsSetTest.vb (revision 397)
+++ MaxCoins/UnitTestProject1/CoinsSetTest.vb (revision 398)
 @@ -8,4 +8,75 @@ 8 8 Assert.AreEqual(CoinsSet.TypeCount, 7) 9 9 End Sub 10 10 11 + 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 + 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 + 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 + 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 + 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 + 11 82 End Class \ No newline at end of file