Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gostnops
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
gostnops
Commits
f7202216
Commit
f7202216
authored
Nov 28, 2019
by
zhanghuiren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comments & invalid testcase
parent
d4151e69
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
16 deletions
+33
-16
integer.go
math/big/integer.go
+15
-3
integer_test.go
math/big/integer_test.go
+18
-13
No files found.
math/big/integer.go
View file @
f7202216
...
...
@@ -18,7 +18,7 @@
package
gxbig
import
(
"
errors
"
"
fmt
"
"math/big"
)
...
...
@@ -30,25 +30,37 @@ type Integer struct {
Value
string
}
func
(
Integer
)
JavaClassName
()
string
{
func
(
i
*
Integer
)
JavaClassName
()
string
{
return
"java.math.BigInteger"
}
// FromString set data from a 10-bases number
func
(
i
*
Integer
)
FromString
(
s
string
)
error
{
intPtr
,
ok
:=
i
.
Int
.
SetString
(
s
,
10
)
if
!
ok
||
intPtr
==
nil
{
return
errors
.
New
(
``
)
return
fmt
.
Errorf
(
"'%s' is not a 10-based number"
,
s
)
}
i
.
Int
=
*
intPtr
return
nil
}
// FromBytes set data from a 10-bases number bytes
func
(
i
*
Integer
)
FromBytes
(
bytes
[]
byte
)
error
{
i
.
Int
=
*
i
.
Int
.
SetBytes
(
bytes
)
return
nil
}
// GetBigInt getter
func
(
i
*
Integer
)
GetBigInt
()
big
.
Int
{
return
i
.
Int
}
// SetBigInt setter
func
(
i
*
Integer
)
SetBigInt
(
bigInt
big
.
Int
)
{
i
.
Int
=
bigInt
}
func
(
i
*
Integer
)
String
()
string
{
return
i
.
Int
.
String
()
}
math/big/integer_test.go
View file @
f7202216
...
...
@@ -21,28 +21,33 @@ import (
"testing"
)
func
TestInteger_FromString
(
t
*
testing
.
T
)
{
type
args
struct
{
s
string
}
func
TestInteger
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
args
args
wantErr
bool
name
string
src
string
wantString
string
wantErr
bool
}{
{
`ten`
,
args
{
`10`
},
false
},
{
`-ten`
,
args
{
`-10`
},
false
},
{
`30digits`
,
args
{
`123456789012345678901234567890`
},
false
},
{
`ten`
,
`10`
,
`10`
,
false
},
{
`-ten`
,
`-10`
,
`-10`
,
false
},
{
`30digits`
,
`123456789012345678901234567890`
,
`123456789012345678901234567890`
,
false
},
{
`invalid-x010`
,
`x010`
,
``
,
true
},
{
`invalid-a010`
,
`a010`
,
``
,
true
},
{
`invalid-10x`
,
`10x`
,
``
,
true
},
{
`invalid-010x`
,
`010x`
,
``
,
true
},
{
`special-010`
,
`010`
,
`10`
,
false
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
i
:=
&
Integer
{}
if
err
:=
i
.
FromString
(
tt
.
args
.
s
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
err
:=
i
.
FromString
(
tt
.
src
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"FromString() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
}
if
got
:=
i
.
String
();
got
!=
tt
.
args
.
s
{
t
.
Errorf
(
"String()
= %v, want %v"
,
got
,
tt
.
args
.
s
)
if
err
==
nil
&&
i
.
String
()
!=
tt
.
wantString
{
t
.
Errorf
(
"String()
got %v, want %v"
,
i
.
String
(),
tt
.
wantString
)
}
})
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment