1 #Region "Microsoft.VisualBasic::b3eacc74567391a5c5234a772d5a7cbb, Microsoft.VisualBasic.Core\Language\Linq\Assert\VectorAssert.vb"
2
3     ' Author:
4     
5     '       asuka (amethyst.asuka@gcmodeller.org)
6     '       xie (genetics@smrucc.org)
7     '       xieguigang (xie.guigang@live.com)
8     
9     ' Copyright (c) 2018 GPL3 Licensed
10     
11     
12     ' GNU GENERAL PUBLIC LICENSE (GPL3)
13     
14     
15     ' This program is free software: you can redistribute it and/or modify
16     ' it under the terms of the GNU General Public License as published by
17     ' the Free Software Foundation, either version 3 of the License, or
18     ' (at your option) any later version.
19     
20     ' This program is distributed in the hope that it will be useful,
21     ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22     ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     ' GNU General Public License for more details.
24     
25     ' You should have received a copy of the GNU General Public License
26     ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28
29
30     ' /********************************************************************************/
31
32     ' Summaries:
33
34     '     Class VectorAssert
35     
36     '         Constructor: (+1 OverloadsSub New
37     
38     '     Class AssertAll
39     
40     '         Constructor: (+1 OverloadsSub New
41     '         Operators: <>, =
42     
43     '     Class AssertAny
44     
45     '         Constructor: (+1 OverloadsSub New
46     '         Operators: <>, =
47     
48     
49     ' /********************************************************************************/
50
51 #End Region
52
53 Imports System.Runtime.CompilerServices
54 Imports Microsoft.VisualBasic.Language.Default
55 Imports Microsoft.VisualBasic.Language.Vectorization
56
57 Namespace Language
58
59     Public Class VectorAssert(Of T)
60
61         Protected ReadOnly vector As Vector(Of T)
62         Protected ReadOnly assert As BinaryAssert(Of Object)
63
64         Default Public ReadOnly Property RunAssert(i%, obj As T) As Boolean
65             <MethodImpl(MethodImplOptions.AggressiveInlining)>
66             Get
67                 Return assert(vector(index:=i), obj)
68             End Get
69         End Property
70
71         Sub New(vector As Vector(Of T), assert As BinaryAssert(Of Object))
72             Me.vector = vector
73             Me.assert = assert
74         End Sub
75     End Class
76
77     Public Class AssertAll(Of T) : Inherits VectorAssert(Of T)
78
79         Sub New(vector As Vector(Of T), assert As BinaryAssert(Of Object))
80             Call MyBase.New(vector, assert)
81         End Sub
82
83         ''' <summary>
84         ''' Does the elements in this vector all equals to a specific value <paramref name="x"/>?
85         ''' </summary>
86         ''' <param name="assert"></param>
87         ''' <param name="x"></param>
88         ''' <returns></returns>
89         ''' 
90         <MethodImpl(MethodImplOptions.AggressiveInlining)>
91         Public Shared Operator =(assert As AssertAll(Of T), x As T) As Boolean
92             Return assert.vector.Sequence.All(Function(i) assert(i, x))
93         End Operator
94
95         <MethodImpl(MethodImplOptions.AggressiveInlining)>
96         Public Shared Operator <>(assert As AssertAll(Of T), x As T) As Boolean
97             Return Not assert = x
98         End Operator
99     End Class
100
101     Public Class AssertAny(Of T) : Inherits VectorAssert(Of T)
102
103         Sub New(vector As Vector(Of T), assert As BinaryAssert(Of Object))
104             Call MyBase.New(vector, assert)
105         End Sub
106
107         ''' <summary>
108         ''' Does the elements in this vector all equals to a specific value <paramref name="x"/>?
109         ''' </summary>
110         ''' <param name="assert"></param>
111         ''' <param name="x"></param>
112         ''' <returns></returns>
113         ''' 
114         <MethodImpl(MethodImplOptions.AggressiveInlining)>
115         Public Shared Operator =(assert As AssertAny(Of T), x As T) As Boolean
116             Return assert.vector.Sequence.Any(Function(i) assert(i, x))
117         End Operator
118
119         <MethodImpl(MethodImplOptions.AggressiveInlining)>
120         Public Shared Operator <>(assert As AssertAny(Of T), x As T) As Boolean
121             Return Not assert = x
122         End Operator
123     End Class
124 End Namespace