Giter Site home page Giter Site logo

ca_mojo's Introduction

ca_mojo

A simple library written in pure Mojo🔥, the new faster, compiled, and stricter superset of Python, by Modular.

Features include:

List

A struct which implements list of Strings with:

var l = List()
l += 1
l += 2
l += 3
var s = String("")
for i in l:
  s += i
s == "123"

test_list.mojo

Tests for List struct. Needs greater list coverage

fu - float utils

Contains:

  • fn str_to_float(s: String) raises -> Float64:
  • fn format_float(f: Float64, dec_places: Int) -> String:
    • format_float rounds up on half, so format_float(3.14159, 4) becomes 3.1416.

test_float_utils.mojo

Tests for fu.str_to_float and fu.format_float.

su - string utils

Contains:

  • fn endswith(input_string: String, suffix: String, start: Int = 0, owned end: Int = -1) raises -> Bool:
  • fn trim(s: String, leading: String, trailing: String) -> String:
  • fn find(s: String, sub: String) -> Int:
  • fn split(s: String, sep: String) -> List:

test_string_utils.mojo

Only tests for fn split(s: String, sep: String) -> List: at the moment.

Matrix

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!

test_matrix.mojo

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 + m2 and 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]]"

TeeTest

A modest test framework. For example...

from teetest import TeeTest
from ca_lib.float_utils import fu

fn 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

fn main():
  TeeTest(
    test_str_to_float_to_rounded_string,
  ).run_tests()

ca_mojo's People

Contributors

carlca avatar soraros avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.