Adding log.gd

This commit is contained in:
Dan Baker 2024-05-02 09:36:31 +01:00
parent eb32d6614e
commit 4522259397
547 changed files with 46844 additions and 0 deletions

View file

@ -0,0 +1,13 @@
class_name FloatFuzzer
extends Fuzzer
var _from: float = 0
var _to: float = 0
func _init(from: float, to: float):
assert(from <= to, "Invalid range!")
_from = from
_to = to
func next_value() -> Variant:
return randf_range(_from, _to)

View file

@ -0,0 +1,39 @@
# Base interface for fuzz testing
# https://en.wikipedia.org/wiki/Fuzzing
class_name Fuzzer
extends RefCounted
# To run a test with a specific fuzzer you have to add defailt argument checked your test case
# all arguments are optional []
# syntax:
# func test_foo([fuzzer = <Fuzzer>], [fuzzer_iterations=<amount>], [fuzzer_seed=<number>])
# example:
# # runs the test 'test_foo' 10 times with a random int value generated by the IntFuzzer
# func test_foo(fuzzer = Fuzzers.randomInt(), fuzzer_iterations=10)
#
# # runs the test 'test_foo2' 1000 times as default with a random seed='101010101'
# func test_foo2(fuzzer = Fuzzers.randomInt(), fuzzer_seed=101010101)
const ITERATION_DEFAULT_COUNT = 1000
const ARGUMENT_FUZZER_INSTANCE := "fuzzer"
const ARGUMENT_ITERATIONS := "fuzzer_iterations"
const ARGUMENT_SEED := "fuzzer_seed"
var _iteration_index :int = 0
var _iteration_limit :int = ITERATION_DEFAULT_COUNT
# generates the next fuzz value
# needs to be implement
func next_value() -> Variant:
push_error("Invalid vall. Fuzzer not implemented 'next_value()'")
return null
# returns the current iteration index
func iteration_index() -> int:
return _iteration_index
# returns the amount of iterations where the fuzzer will be run
func iteration_limit() -> int:
return _iteration_limit

View file

@ -0,0 +1,32 @@
class_name IntFuzzer
extends Fuzzer
enum {
NORMAL,
EVEN,
ODD
}
var _from :int = 0
var _to : int = 0
var _mode : int = NORMAL
func _init(from: int, to: int, mode :int = NORMAL):
assert(from <= to, "Invalid range!")
_from = from
_to = to
_mode = mode
func next_value() -> Variant:
var value := randi_range(_from, _to)
match _mode:
NORMAL:
return value
EVEN:
return int((value / 2.0) * 2)
ODD:
return int((value / 2.0) * 2 + 1)
_:
return value

View file

@ -0,0 +1,64 @@
class_name StringFuzzer
extends Fuzzer
const DEFAULT_CHARSET = "a-zA-Z0-9+-_"
var _min_length :int
var _max_length :int
var _charset :PackedByteArray
func _init(min_length :int,max_length :int,pattern :String = DEFAULT_CHARSET):
assert(min_length>0 and min_length < max_length)
assert(not null or not pattern.is_empty())
_min_length = min_length
_max_length = max_length
_charset = StringFuzzer.extract_charset(pattern)
static func extract_charset(pattern :String) -> PackedByteArray:
var reg := RegEx.new()
if reg.compile(pattern) != OK:
push_error("Invalid pattern to generate Strings! Use e.g 'a-zA-Z0-9+-_'")
return PackedByteArray()
var charset := Array()
var char_before := -1
var index := 0
while index < pattern.length():
var char_current := pattern.unicode_at(index)
# - range token at first or last pos?
if char_current == 45 and (index == 0 or index == pattern.length()-1):
charset.append(char_current)
index += 1
continue
index += 1
# range starts
if char_current == 45 and char_before != -1:
var char_next := pattern.unicode_at(index)
var characters := build_chars(char_before, char_next)
for character in characters:
charset.append(character)
char_before = -1
index += 1
continue
char_before = char_current
charset.append(char_current)
return PackedByteArray(charset)
static func build_chars(from :int, to :int) -> Array:
var characters := Array()
for character in range(from+1, to+1):
characters.append(character)
return characters
func next_value() -> Variant:
var value := PackedByteArray()
var max_char := len(_charset)
var length :int = max(_min_length, randi() % _max_length)
for i in length:
value.append(_charset[randi() % max_char])
return value.get_string_from_ascii()

View file

@ -0,0 +1,18 @@
class_name Vector2Fuzzer
extends Fuzzer
var _from :Vector2
var _to : Vector2
func _init(from: Vector2,to: Vector2):
assert(from <= to) #,"Invalid range!")
_from = from
_to = to
func next_value() -> Variant:
var x = randf_range(_from.x, _to.x)
var y = randf_range(_from.y, _to.y)
return Vector2(x, y)

View file

@ -0,0 +1,19 @@
class_name Vector3Fuzzer
extends Fuzzer
var _from :Vector3
var _to : Vector3
func _init(from: Vector3,to: Vector3):
assert(from <= to) #,"Invalid range!")
_from = from
_to = to
func next_value() -> Variant:
var x = randf_range(_from.x, _to.x)
var y = randf_range(_from.y, _to.y)
var z = randf_range(_from.z, _to.z)
return Vector3(x, y, z)