FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
BaseNcoding/BaseNcoding.Tests/BaseNTests.cs at master · KvanTTT/BaseNcoding · GitHub
KvanTTT
/
BaseNcoding
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
49
Code
Issues
4
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
BaseNcoding
/
BaseNcoding.Tests
/
BaseNTests.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
137 lines (124 loc) · 3.96 KB
Breadcrumbs
BaseNcoding
/
BaseNcoding.Tests
/
BaseNTests.cs
Copy path
File metadata and controls
137 lines (124 loc) · 3.96 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using
NUnit
.
Framework
;
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Diagnostics
;
using
System
.
Text
;
namespace
BaseNcoding
.
Tests
{
[
TestFixture
]
public
class
BaseNTests
{
[
Test
]
public
void
BaseNCompareToBase64
(
)
{
string
s
=
"aaa"
;
var
converter
=
new
BaseN
(
Base64
.
DefaultAlphabet
)
;
string
encoded
=
converter
.
EncodeString
(
s
)
;
string
base64Standard
=
Convert
.
ToBase64String
(
Encoding
.
UTF8
.
GetBytes
(
s
)
)
;
Assert
.
AreEqual
(
base64Standard
,
encoded
)
;
}
[
Test
]
public
void
ReverseOrder
(
)
{
var
converter
=
new
BaseN
(
StringGenerator
.
GetAlphabet
(
54
)
,
32
,
null
,
true
)
;
var
original
=
"sdfrewwekjthkjh"
;
var
encoded
=
converter
.
EncodeString
(
original
)
;
var
decoded
=
converter
.
DecodeToString
(
encoded
)
;
Assert
.
AreEqual
(
original
,
decoded
)
;
}
[
Test
]
public
void
GetOptimalBitsCount
(
)
{
Assert
.
AreEqual
(
5
,
BaseN
.
GetOptimalBitsCount2
(
32
,
out
var
charsCountInBits
)
)
;
Assert
.
AreEqual
(
6
,
BaseN
.
GetOptimalBitsCount2
(
64
,
out
charsCountInBits
)
)
;
Assert
.
AreEqual
(
32
,
BaseN
.
GetOptimalBitsCount2
(
85
,
out
charsCountInBits
)
)
;
Assert
.
AreEqual
(
13
,
BaseN
.
GetOptimalBitsCount2
(
91
,
out
charsCountInBits
)
)
;
StringBuilder
builder
=
new
StringBuilder
(
)
;
for
(
int
i
=
2
;
i
<=
256
;
i
++
)
{
var
bits
=
BaseBigN
.
GetOptimalBitsCount2
(
(
uint
)
i
,
out
charsCountInBits
,
512
)
;
double
ratio
=
(
double
)
bits
/
charsCountInBits
;
builder
.
AppendLine
(
bits
+
" "
+
charsCountInBits
+
" "
+
ratio
.
ToString
(
"0.0000000"
)
)
;
}
string
str
=
builder
.
ToString
(
)
;
}
[
Test
]
public
void
EncodeDecodeBaseN
(
)
{
byte
testByte
=
157
;
List
<
byte
>
bytes
=
new
List
<
byte
>
(
)
;
for
(
uint
radix
=
2
;
radix
<
1000
;
radix
++
)
{
var
baseN
=
new
BaseN
(
StringGenerator
.
GetAlphabet
(
(
int
)
radix
)
,
64
)
;
int
testBytesCount
=
Math
.
Max
(
(
baseN
.
BlockBitsCount
+
7
)
/
8
,
(
int
)
baseN
.
BlockCharsCount
)
;
bytes
.
Clear
(
)
;
for
(
int
i
=
0
;
i
<=
testBytesCount
+
1
;
i
++
)
{
var
array
=
bytes
.
ToArray
(
)
;
var
encoded
=
baseN
.
Encode
(
array
)
;
var
decoded
=
baseN
.
Decode
(
encoded
)
;
CollectionAssert
.
AreEqual
(
array
,
decoded
)
;
bytes
.
Add
(
testByte
)
;
}
}
}
[
Test
]
public
void
EncodeDecodeBaseBigN
(
)
{
byte
testByte
=
157
;
List
<
byte
>
bytes
=
new
List
<
byte
>
(
)
;
for
(
uint
radix
=
2
;
radix
<
1000
;
radix
++
)
{
var
baseN
=
new
BaseBigN
(
StringGenerator
.
GetAlphabet
(
(
int
)
radix
)
,
256
)
;
int
testBytesCount
=
Math
.
Max
(
(
baseN
.
BlockBitsCount
+
7
)
/
8
,
baseN
.
BlockCharsCount
)
;
bytes
.
Clear
(
)
;
for
(
int
i
=
0
;
i
<=
testBytesCount
+
1
;
i
++
)
{
var
array
=
bytes
.
ToArray
(
)
;
var
encoded
=
baseN
.
Encode
(
array
)
;
var
decoded
=
baseN
.
Decode
(
encoded
)
;
CollectionAssert
.
AreEqual
(
array
,
decoded
)
;
bytes
.
Add
(
testByte
)
;
}
}
}
[
Test
]
public
void
EncodeDecodeBaseBigNMaxCompression
(
)
{
byte
testByte
=
157
;
List
<
byte
>
bytes
=
new
List
<
byte
>
(
)
;
for
(
uint
radix
=
2
;
radix
<
1000
;
radix
++
)
{
var
baseN
=
new
BaseBigN
(
StringGenerator
.
GetAlphabet
(
(
int
)
radix
)
,
256
,
null
,
false
,
false
,
true
)
;
int
testBytesCount
=
Math
.
Max
(
(
baseN
.
BlockBitsCount
+
7
)
/
8
,
baseN
.
BlockCharsCount
)
;
bytes
.
Clear
(
)
;
for
(
int
i
=
0
;
i
<=
testBytesCount
+
1
;
i
++
)
{
var
array
=
bytes
.
ToArray
(
)
;
var
encoded
=
baseN
.
Encode
(
array
)
;
var
decoded
=
baseN
.
Decode
(
encoded
)
;
CollectionAssert
.
AreEqual
(
array
,
decoded
)
;
bytes
.
Add
(
testByte
)
;
}
}
}
[
Test
]
public
void
EncodeDecodeParallel
(
)
{
var
randomString
=
StringGenerator
.
GetRandom
(
10000000
,
true
)
;
var
baseN
=
new
BaseN
(
StringGenerator
.
GetAlphabet
(
85
)
)
;
var
stopwatch
=
new
Stopwatch
(
)
;
stopwatch
.
Start
(
)
;
var
baseNEncoded
=
baseN
.
EncodeString
(
randomString
)
;
stopwatch
.
Stop
(
)
;
var
baseNTime
=
stopwatch
.
Elapsed
;
stopwatch
.
Restart
(
)
;
baseN
.
Parallel
=
true
;
var
baseNEncodedParallel
=
baseN
.
EncodeString
(
randomString
)
;
stopwatch
.
Stop
(
)
;
var
baseNParallelTime
=
stopwatch
.
Elapsed
;
CollectionAssert
.
AreEqual
(
baseNEncoded
,
baseNEncodedParallel
)
;
Assert
.
Less
(
baseNParallelTime
,
baseNTime
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL