import tohu
from tohu.v6.primitive_generators import *
from tohu.v6.generator_dispatch import *
from tohu.v6.utils import print_generated_sequence

print(f'Tohu version: {tohu.__version__}')

"""
Explanation: Primitive generators
This notebook contains tests for tohu's primitive generators.
End of explanation
"""


g = Constant('quux')

print_generated_sequence(g, num=10, seed=12345)

"""
Explanation: Constant
Constant simply returns the same, constant value every time.
End of explanation
"""


g1 = Boolean()
g2 = Boolean(p=0.8)

print_generated_sequence(g1, num=20, seed=12345)
print_generated_sequence(g2, num=20, seed=99999)

"""
Explanation: Boolean
Boolean returns either True or False, optionally with different probabilities.
End of explanation
"""


g = Incremental(start=200, step=4)

print_generated_sequence(g, num=20, seed=12345)

"""
Explanation: Incremental
Incremental returns a sequence of numbers that increase in regular steps.
End of explanation
"""


g = Integer(low=100, high=200)

print_generated_sequence(g, num=20, seed=12345)

"""
Explanation: Integer
Integer returns a random integer between low and high (both inclusive).
End of explanation
"""


g = Float(low=2.3, high=4.2)

print_generated_sequence(g, num=10, sep='\n', fmt='.12f', seed=12345)

"""
Explanation: Float
Float returns a random float between low and high (both inclusive).
End of explanation
"""


g = CharString(length=15)
print_generated_sequence(g, num=5, seed=12345)
print_generated_sequence(g, num=5, seed=99999)

"""
Explanation: CharString
End of explanation
"""


g = CharString(length=12, charset="ABCDEFG")
print_generated_sequence(g, num=5, sep='\n', seed=12345)

"""
Explanation: It is possible to explicitly specify the character set.
End of explanation
"""


g1 = CharString(length=12, charset="<lowercase>")
g2 = CharString(length=12, charset="<alphanumeric_uppercase>")
print_generated_sequence(g1, num=5, sep='\n', seed=12345); print()
print_generated_sequence(g2, num=5, sep='\n', seed=12345)

"""
Explanation: There are also a few pre-defined character sets.
End of explanation
"""


g = DigitString(length=15)
print_generated_sequence(g, num=5, seed=12345)
print_generated_sequence(g, num=5, seed=99999)

"""
Explanation: DigitString
DigitString is the same as CharString with charset='0123456789'.
End of explanation
"""


g = Sequential(prefix='Foo_', digits=3)

"""
Explanation: Sequential
Generates a sequence of sequentially numbered strings with a given prefix.
End of explanation
"""


g.reset()
print_generated_sequence(g, num=5)
print_generated_sequence(g, num=5)
print()
g.reset()
print_generated_sequence(g, num=5)

"""
Explanation: Calling reset() on the generator makes the numbering start from 1 again.
End of explanation
"""


g.reset(seed=12345); print_generated_sequence(g, num=5)
g.reset(seed=99999); print_generated_sequence(g, num=5)

"""
Explanation: Note that the method Sequential.reset() supports the seed argument for consistency with other generators, but its value is ignored - the generator is simply reset to its initial value. This is illustrated here:
End of explanation
"""


g = HashDigest(length=6)

print_generated_sequence(g, num=10, seed=12345)

"""
Explanation: HashDigest
HashDigest returns hex strings representing hash digest values (or alternatively raw bytes).
HashDigest hex strings (uppercase)
End of explanation
"""


g = HashDigest(length=6, uppercase=False)

print_generated_sequence(g, num=10, seed=12345)

"""
Explanation: HashDigest hex strings (lowercase)
End of explanation
"""


g = HashDigest(length=10, as_bytes=True)

print_generated_sequence(g, num=5, seed=12345, sep='\n')

"""
Explanation: HashDigest byte strings
End of explanation
"""


g1 = NumpyRandomGenerator(method="normal", loc=3.0, scale=5.0)
g2 = NumpyRandomGenerator(method="poisson", lam=30)
g3 = NumpyRandomGenerator(method="exponential", scale=0.3)

g1.reset(seed=12345); print_generated_sequence(g1, num=4)
g2.reset(seed=12345); print_generated_sequence(g2, num=15)
g3.reset(seed=12345); print_generated_sequence(g3, num=4)

"""
Explanation: NumpyRandomGenerator
This generator can produce random numbers using any of the random number generators supported by numpy.
End of explanation
"""


g = FakerGenerator(method='name')

print_generated_sequence(g, num=8, seed=12345)

"""
Explanation: FakerGenerator
FakerGenerator gives access to any of the methods supported by the faker module. Here are a couple of examples.
Example: random names
End of explanation
"""


g = FakerGenerator(method='address')

print_generated_sequence(g, num=8, seed=12345, sep='\n---\n')

"""
Explanation: Example: random addresses
End of explanation
"""


g = Timestamp(start="2018-01-01 11:22:33", end="2018-02-13 12:23:34")

type(next(g))

print_generated_sequence(g, num=10, seed=12345, sep='\n')

g = Timestamp(start="2018-01-01 11:22:33", end="2018-02-13 12:23:34").strftime("%-d %b %Y, %H:%M (%a)")

type(next(g))

print_generated_sequence(g, num=10, seed=12345, sep='\n')

"""
Explanation: Timestamp
End of explanation
"""


g = Date(start="2018-01-01", end="2018-02-13")

type(next(g))

print_generated_sequence(g, num=10, seed=12345, sep='\n')

g = Date(start="2018-01-01", end="2018-02-13").strftime("%-d %b %Y")

type(next(g))

print_generated_sequence(g, num=10, seed=12345, sep='\n')

"""
Explanation: Date
End of explanation
"""


