A simple library written in pure Mojo🔥, the new faster, compiled, and stricter superset of Python, by Modular.
The code is written against the latest nightly build of Mojo.
Use modular update nightly/mojo to get the latest version.
Features include:
Contains:
def str_to_float(s: String) raises -> Float64:def format_float(f: Float64, dec_places: Int) -> String:format_floatrounds up on half, soformat_float(3.14159, 4)becomes3.1416.
Tests for fu.str_to_float and fu.format_float.
Contains:
def endswith(input_string: String, suffix: String, start: Int = 0, owned end: Int = -1) raises -> Bool:def trim(s: String, leading: String, trailing: String) -> String:def find(s: String, sub: String) -> Int:def split(s: String, sep: String) -> List:
Only tests for def split(s: String, sep: String) -> List: at the moment.
A struct which represents a simple 2 dimensional matrix capable of storing Float64 numbers.
Contains many functions a lot of which have not even been tested casually, var alone by formal unit tests. Proceed with caution!
Only tests for initialising from string...
var m1 = Matrix("[[1.1, 1.1, 1.1], [2.2, 2.2, 2.2], [3.3, 3.3, 3.3], [4.4, 4.4, 4.4]]")and for adding...var m3 = m1 + m2and for converting back to string...return m3.string_to(1) == "[[2.2, 2.2, 2.2], [3.3, 3.3, 3.3], [4.4, 4.4, 4.4], [5.5, 5.5, 5.5]]"
A modest test framework. For example...
from teetest import TeeTest
from ca_lib.float_utils import fu
def test_str_to_float_to_rounded_string() raises -> Tuple[Bool, StringLiteral]:
alias pi_str = "3.1415926234534563"
var pi = fu.str_to_float(pi_str)
var assert1 = fu.format_float(pi, 5) == "3.14159"
var assert2 = fu.format_float(pi, 6) == "3.141593"
var assert3 = fu.format_float(pi, 7) == "3.1415926"
return assert1 and assert2 and assert3,
__source_location().function_name
def main():
TeeTest(
test_str_to_float_to_rounded_string,
).run_tests()found in ca_mojo/ca_lib/preset_parser/presetparser.mojo
A proof-of-concept for using Mojo for binary file reading.
It parses the initial metadata found in a Bitwig .bwpreset file and displays it to the console.
To save you from too much folder diving, you can run it from the root folder with...
Usage: mojo parser.mojo <path-to-preset-file>
Eg: mojo parser.mojo ./Diffusion.bwpreset
or: mojo parser.mojo ./Binaural_Organ_Device.bwpreset
It uses some path related functions in ca_mojo/ca_lib/sysutils.
In the file, parser.mojo, you can set debug = True to get more information about the parsing process.
var pp = presetparser.PresetParser()
pp.debug = False
pp.process_preset(filename)
print()