{"id":15830102,"url":"https://github.com/krzema12/vis-assert","last_synced_at":"2025-04-01T17:33:17.739Z","repository":{"id":55385284,"uuid":"163332876","full_name":"krzema12/vis-assert","owner":"krzema12","description":"Test the shape of your functions!","archived":false,"fork":false,"pushed_at":"2021-03-14T12:54:47.000Z","size":509,"stargazers_count":6,"open_issues_count":6,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T19:48:37.746Z","etag":null,"topics":["ascii-art","audio","audio-analysis","audio-processing","functional-programming","game-development","js","jvm","kotlin","kotlin-js","kotlin-jvm","kotlin-library","kotlin-multiplatform","kotlin-test","kotlin-testing","multiplatform","tdd","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krzema12.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-27T20:19:59.000Z","updated_at":"2023-06-15T07:54:29.000Z","dependencies_parsed_at":"2022-08-14T23:10:17.044Z","dependency_job_id":null,"html_url":"https://github.com/krzema12/vis-assert","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzema12%2Fvis-assert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzema12%2Fvis-assert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzema12%2Fvis-assert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzema12%2Fvis-assert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krzema12","download_url":"https://codeload.github.com/krzema12/vis-assert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246635945,"owners_count":20809331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ascii-art","audio","audio-analysis","audio-processing","functional-programming","game-development","js","jvm","kotlin","kotlin-js","kotlin-jvm","kotlin-library","kotlin-multiplatform","kotlin-test","kotlin-testing","multiplatform","tdd","unit-testing"],"created_at":"2024-10-05T11:04:39.217Z","updated_at":"2025-04-01T17:33:17.485Z","avatar_url":"https://github.com/krzema12.png","language":"Kotlin","readme":"[![Build Status](https://travis-ci.com/krzema12/vis-assert.svg?branch=master)](https://travis-ci.com/krzema12/vis-assert) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/it.krzeminski.vis-assert/vis-assert/badge.svg)](https://maven-badges.herokuapp.com/maven-central/it.krzeminski.vis-assert/vis-assert) [![codecov](https://codecov.io/gh/krzema12/vis-assert/branch/master/graph/badge.svg)](https://codecov.io/gh/krzema12/vis-assert)\n\n# 🧪 This library is experimental!\n\nIts API is not stabilized yet, and writing tests is still a bit tedious. Use at your own risk. Looking forward to your feedback :)\n\n# What is vis-assert?\n\nIt's a Kotlin library to write visually appealing ASCII-art-like test assertions for math functions. For example, you\ncan test that your `(Float) -\u003e Float` function describing a sine wave produces proper values. Or if you have a game\nwhere the player jumps, you can describe player's vertical position as a function of time - you could test this function\nto make sure that the jump movement is fluent and fast enough.\n\nUnder the hood, each such ASCII visualisation is translated into a collection of *constraints*, where each constraint\nlooks at a single X value of the function and performs a certain check on its Y value at this point.\n\n# Installation\n\nIn your `build.gradle` or `build.gradle.kts`:\n\n```\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    testCompile(\"it.krzeminski.vis-assert:vis-assert:0.4.1-beta\")\n}\n\n// or\n\nkotlin {\n    sourceSets {\n        val ...Test by getting {\n            dependencies {\n                implementation(\"it.krzeminski.vis-assert:vis-assert:0.4.1-beta\")\n            }\n        }\n    }\n}\n```\n\n# Examples\n\n```kotlin\n@Test\nfun sineWaveFor2HzOnePeriod() {\n    assertFunctionConformsTo(\n            functionUnderTest = sineWave(frequency = 2.0f),\n            visualisation = {\n                row(1.0f,   \"        IIXII                            \")\n                row(        \"     III     III                         \")\n                row(        \"    I           I                        \")\n                row(        \"  II             II                      \")\n                row(        \" I                 I                     \")\n                row(0.0f,   \"X                   I                   I\")\n                row(        \"                     I                 I \")\n                row(        \"                      II             II  \")\n                row(        \"                        I           I    \")\n                row(        \"                         III     III     \")\n                row(-1.0f,  \"                            IIIII        \")\n                xAxis {\n                    markers(\"|                   |                   |\")\n                    values( 0.0f,               0.25f,              0.5f)\n                }\n            })\n}\n```\n\nor for high-frequency function and higher sampling:\n\n```kotlin\n@Test\nfun assertFunctionConformsToForHighFrequencyFunctionWhenAssertionsAreFulfilledAndSamplingHigherThan1IsUsed() {\n    assertFunctionConformsTo(\n        functionUnderTest = { x: Float -\u003e (sin(100*x) * sin(x) * x * 0.3).toFloat() },\n        samplesPerCharacter = 100,\n        visualisation = {\n            row( 2.0f,  \"                                                                   \")\n            row(        \"                                                                   \")\n            row(        \"                                               IIIIIIIIIIIIII      \")\n            row( 1.0f,  \"                                           IIIIIIIIIIIIIIIIIIIII   \")\n            row(        \"                   IIIIIIII             IIIIIIIIIIIIIIIIIIIIIIIIIII\")\n            row(        \"         IIIIIIIIIIIIIIIIIIIIIIII   IIIIIIIIIIIIIIIIIIIIIIIIIIIIIII\")\n            row( 0.0f,  \"IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII\")\n            row(        \"         IIIIIIIIIIIIIIIIIIIIIIII    IIIIIIIIIIIIIIIIIIIIIIIIIIIIII\")\n            row(        \"                  IIIIIIII              IIIIIIIIIIIIIIIIIIIIIIIIIII\")\n            row(-1.0f,  \"                                            IIIIIIIIIIIIIIIIIIII   \")\n            row(        \"                                               IIIIIIIIIIIIII      \")\n            row(        \"                                                                   \")\n            row(-2.0f,  \"                                                                   \")\n            xAxis {\n                markers(\"|          |          |          |          |          |          |\")\n                values( 0.0f,      1.0f,      2.0f,      3.0f,      4.0f,      5.0f,      6.0f)\n            }\n        }\n    )\n}\n```\n\nWhere:\n\n* `I` characters mean that for a given X argument, the function's value can be in a certain range around a given Y\n  value. Also, this constraint is \"strict\", which means that making it wider or narrower vertically would make the\n  assertion fail. In this example, each `I` character has a tolerance of +/- 0.1. The tolerance is calculated based on\n  the vertical axis description.\n* `X` characters mean that for a given X argument, the function's value has to **exactly** match the given Y value.\n\nThere's also `i` constraint, which just checks that all values are in a certain range.\n\nMore examples can be found in unit tests for [krzema12/fsynth](https://github.com/krzema12/fsynth) - a project that\nvis-assert was created for.\n\n# Limitations\n\n* the library performs sampling, as given by the `xAxis` description and `samplesPerCharacter` parameter. It means that\n  if two subsequent X values are 0.2 and 0.3, and not enough sampling rate is given, the library may not check what\n  happens for 0.25 or 0.20001. In most cases, such simple sampling is enough.\n* only `(Float) -\u003e Float` functions are currently supported. Mitigation: it's possible to assert on any other function,\n  as long as it can be presented as a `(Float) -\u003e Float` function. See [this example](https://github.com/krzema12/fsynth/blob/feb05893b14fba0f7a780dc546d1ad806bb2bfbf/core/src/test/kotlin/it/krzeminski/fsynth/RenderingTest.kt#L23)\n  for adapting an `(Int) -\u003e Float` function\n* when assertions fail, the current message just says about failed first (x, y) constraint, going from the left. It's\n  thus quite time-consuming to write a test. Ideally, if the assertion fails, vis-assert should show how the ASCII\n  visualisation could look like.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrzema12%2Fvis-assert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrzema12%2Fvis-assert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrzema12%2Fvis-assert/lists"}