mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-20 10:13:26 +01:00
add respective generators and specs for ScriptNumber, Block, BlockHeader, CompactSizeUInt
This commit is contained in:
parent
6d4763acf4
commit
32b2da3f28
@ -80,7 +80,6 @@ class UInt32Spec extends Properties("UInt32") with BitcoinSLogger {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
property("== & !=") = {
|
||||
Prop.forAll(NumberGenerator.uInt32s, NumberGenerator.uInt32s) { (num1 : UInt32, num2 : UInt32) =>
|
||||
if (num1.underlying == num2.underlying) num1 == num2
|
||||
|
@ -13,4 +13,9 @@ class CompactSizeUIntSpec extends Properties("CompactSizeUIntSpec") {
|
||||
Prop.forAll(NumberGenerator.positiveLongs) { num : Long =>
|
||||
CompactSizeUInt.parseCompactSizeUInt(CompactSizeUInt(num).hex).num == num
|
||||
}
|
||||
//:TODO Remove one of these
|
||||
property("Serialization symmetry with separate generator") =
|
||||
Prop.forAll(NumberGenerator.compactSizeUInts) { compact : CompactSizeUInt =>
|
||||
CompactSizeUInt(compact.num, compact.size) == compact
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package org.bitcoins.core.protocol.blockchain
|
||||
|
||||
import org.bitcoins.core.gen.BlockchainElementsGenerator
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
* Created by tom on 7/6/16.
|
||||
*/
|
||||
class BlockHeaderSpec extends Properties("BlockHeaderSpec") {
|
||||
property("serialization symmetry") =
|
||||
Prop.forAll(BlockchainElementsGenerator.blockHeader) { header =>
|
||||
BlockHeader(header.version, header.previousBlockHash, header.merkleRootHash, header.time, header.nBits, header.nonce) == header
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package org.bitcoins.core.script.constant
|
||||
|
||||
import com.oracle.webservices.internal.api.message.PropertySet.Property
|
||||
import org.bitcoins.core.gen.NumberGenerator
|
||||
import org.bitcoins.core.number.UInt32
|
||||
import org.bitcoins.core.util.BitcoinSLogger
|
||||
import org.scalacheck.{Prop, Properties}
|
||||
|
||||
/**
|
||||
* Created by tom on 7/5/16.
|
||||
*/
|
||||
class ScriptNumberSpec extends Properties("ScriptNumberSpec") with BitcoinSLogger {
|
||||
property("Additive identity") =
|
||||
Prop.forAll(NumberGenerator.scriptNumbers) { num : ScriptNumber =>
|
||||
num + ScriptNumber.zero == num
|
||||
}
|
||||
property("Subtraction identity") =
|
||||
Prop.forAll(NumberGenerator.scriptNumbers) { num : ScriptNumber =>
|
||||
num - ScriptNumber.zero == num
|
||||
}
|
||||
property("Multiplicative identity") =
|
||||
Prop.forAll(NumberGenerator.scriptNumbers) { num : ScriptNumber =>
|
||||
num * ScriptNumber.one == num
|
||||
}
|
||||
property("< >=") =
|
||||
Prop.forAll(NumberGenerator.scriptNumbers, NumberGenerator.scriptNumbers) { (num1 : ScriptNumber, num2 : ScriptNumber) =>
|
||||
if (num1.underlying < num2.underlying) num1 < num2
|
||||
else num1 >= num2
|
||||
}
|
||||
property("> <=") =
|
||||
Prop.forAll(NumberGenerator.scriptNumbers, NumberGenerator.scriptNumbers) { (num1 : ScriptNumber, num2 : ScriptNumber) =>
|
||||
if (num1.underlying > num2.underlying) num1 > num2
|
||||
else num1 <= num2
|
||||
}
|
||||
property("== & !=") = {
|
||||
Prop.forAll(NumberGenerator.scriptNumbers, NumberGenerator.scriptNumbers) { (num1 : ScriptNumber, num2 : ScriptNumber) =>
|
||||
if (num1.underlying == num2.underlying) num1 == num2
|
||||
else num1 != num2
|
||||
}
|
||||
}
|
||||
property("add two script numbers") =
|
||||
Prop.forAll(NumberGenerator.scriptNumbers, NumberGenerator.scriptNumbers) { (num1 : ScriptNumber, num2: ScriptNumber) =>
|
||||
num1 + num2 == ScriptNumber(num1.underlying + num2.underlying)
|
||||
}
|
||||
property("subtract a script number from another script number") =
|
||||
Prop.forAll(NumberGenerator.scriptNumbers, NumberGenerator.scriptNumbers) { (num1 : ScriptNumber, num2: ScriptNumber) =>
|
||||
num1 - num2 == ScriptNumber(num1.underlying - num2.underlying)
|
||||
}
|
||||
property("multiply two script numbers") =
|
||||
Prop.forAll(NumberGenerator.scriptNumbers, NumberGenerator.scriptNumbers) { (num1 : ScriptNumber, num2: ScriptNumber) =>
|
||||
num1 * num2 == ScriptNumber(num1.underlying * num2.underlying)
|
||||
}
|
||||
property("multiply a script number by zero should return zero") =
|
||||
Prop.forAll(NumberGenerator.scriptNumbers) { (num1 : ScriptNumber) =>
|
||||
num1 * ScriptNumber.zero == ScriptNumber.zero
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user