/usr/share/doc/nunit/examples/vb/money/Money.vb is in libnunit-doc 2.5.10.11092+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | ' ****************************************************************
' This is free software licensed under the NUnit license. You
' may obtain a copy of the license as well as information regarding
' copyright ownership at http://nunit.org/?p=license&r=2.4.
' ****************************************************************
Option Explicit On
Namespace NUnit.Samples
' A Simple Money.
Public Class Money
Implements IMoney
Private fAmount As Int32
Private fCurrency As String
' Constructs a money from a given amount and currency.
Public Sub New(ByVal amount As Int32, ByVal currency As String)
Me.fAmount = amount
Me.fCurrency = currency
End Sub
' Adds a money to this money. Forwards the request
' to the AddMoney helper.
Public Overloads Function Add(ByVal m As IMoney) As IMoney Implements IMoney.Add
Return m.AddMoney(Me)
End Function
Public Overloads Function AddMoney(ByVal m As Money) As IMoney Implements IMoney.AddMoney
If m.Currency.Equals(Currency) Then
Return New Money(Amount + m.Amount, Currency)
End If
Return New MoneyBag(Me, m)
End Function
Public Function AddMoneyBag(ByVal s As MoneyBag) As IMoney Implements IMoney.AddMoneyBag
Return s.AddMoney(Me)
End Function
Public ReadOnly Property Amount() As Integer
Get
Return fAmount
End Get
End Property
Public ReadOnly Property Currency() As String
Get
Return fCurrency
End Get
End Property
Public Overloads Overrides Function Equals(ByVal anObject As Object) As Boolean
If IsZero And TypeOf anObject Is IMoney Then
Dim aMoney As IMoney = anObject
Return aMoney.IsZero
End If
If TypeOf anObject Is Money Then
Dim aMoney As Money = anObject
If (IsZero) Then
Return aMoney.IsZero
End If
Return Currency.Equals(aMoney.Currency) And Amount.Equals(aMoney.Amount)
End If
Return False
End Function
Public Overrides Function GetHashCode() As Int32
Return fCurrency.GetHashCode() + fAmount
End Function
Public ReadOnly Property IsZero() As Boolean Implements IMoney.IsZero
Get
Return Amount.Equals(0)
End Get
End Property
Public Function Multiply(ByVal factor As Integer) As IMoney Implements IMoney.Multiply
Return New Money(Amount * factor, Currency)
End Function
Public Function Negate() As IMoney Implements IMoney.Negate
Return New Money(-Amount, Currency)
End Function
Public Function Subtract(ByVal m As IMoney) As IMoney Implements IMoney.Subtract
Return Add(m.Negate())
End Function
Public Overrides Function ToString() As String
Return String.Format("[{0} {1}]", Amount, Currency)
End Function
End Class
End Namespace
|