mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Set up javascript tests
This commit is contained in:
@@ -26,16 +26,27 @@ repositories {
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
js()
|
||||
|
||||
targets {
|
||||
def sdkName = System.getenv('SDK_NAME')
|
||||
def isIphone = sdkName?.startsWith("iphoneos")
|
||||
def iosPreset = isIphone ? presets.iosArm64 : presets.iosX64
|
||||
|
||||
fromPreset(iosPreset, 'ios') {
|
||||
compilations.main.outputKinds('FRAMEWORK')
|
||||
}
|
||||
|
||||
fromPreset(presets.jvm, 'jvm') {
|
||||
|
||||
}
|
||||
|
||||
fromPreset(presets.js, 'js') {
|
||||
compilations.main.kotlinOptions {
|
||||
moduleKind = "commonjs"
|
||||
}
|
||||
compilations.test.kotlinOptions {
|
||||
moduleKind = "commonjs"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
1
core/gradle.properties
Normal file
1
core/gradle.properties
Normal file
@@ -0,0 +1 @@
|
||||
org.gradle.parallel=true
|
||||
@@ -22,48 +22,44 @@ package org.isoron.uhabits.models
|
||||
import org.isoron.platform.time.*
|
||||
import org.isoron.uhabits.models.Checkmark.Companion.CHECKED_MANUAL
|
||||
import org.isoron.uhabits.models.Frequency.Companion.DAILY
|
||||
import org.isoron.uhabits.models.HabitType.*
|
||||
import org.isoron.uhabits.models.ScoreList.Companion.compute
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import java.lang.Math.*
|
||||
import kotlin.test.*
|
||||
|
||||
class ScoreListTest {
|
||||
val epsilon = 1e-6
|
||||
val today = LocalDate(2019, 1, 1)
|
||||
|
||||
@Test
|
||||
fun `compute with daily habit`() {
|
||||
fun computeWithDailyHabit() {
|
||||
val freq = DAILY
|
||||
var check = 1
|
||||
assertEquals(compute(freq, 0.0, check), 0.051922, epsilon)
|
||||
assertEquals(compute(freq, 0.5, check), 0.525961, epsilon)
|
||||
assertEquals(compute(freq, 0.75, check), 0.762980, epsilon)
|
||||
assertEquals(compute(freq, 0.0, check), 0.051922)
|
||||
assertEquals(compute(freq, 0.5, check), 0.525961)
|
||||
assertEquals(compute(freq, 0.75, check), 0.762980)
|
||||
|
||||
check = 0
|
||||
assertEquals(compute(freq, 0.0, check), 0.0, epsilon)
|
||||
assertEquals(compute(freq, 0.5, check), 0.474039, epsilon)
|
||||
assertEquals(compute(freq, 0.75, check), 0.711058, epsilon)
|
||||
assertEquals(compute(freq, 0.0, check), 0.0)
|
||||
assertEquals(compute(freq, 0.5, check), 0.474038)
|
||||
assertEquals(compute(freq, 0.75, check), 0.711058)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `compute with non-daily habit`() {
|
||||
fun computeWithNonDailyHabit() {
|
||||
var check = 1
|
||||
val freq = Frequency(1, 3)
|
||||
assertEquals(compute(freq, 0.0, check), 0.017615, epsilon)
|
||||
assertEquals(compute(freq, 0.5, check), 0.508807, epsilon)
|
||||
assertEquals(compute(freq, 0.75, check), 0.754404, epsilon)
|
||||
assertEquals(compute(freq, 0.0, check), 0.017615)
|
||||
assertEquals(compute(freq, 0.5, check), 0.508807)
|
||||
assertEquals(compute(freq, 0.75, check), 0.754403)
|
||||
|
||||
check = 0
|
||||
assertEquals(compute(freq, 0.0, check), 0.0, epsilon)
|
||||
assertEquals(compute(freq, 0.5, check), 0.491192, epsilon)
|
||||
assertEquals(compute(freq, 0.75, check), 0.736788, epsilon)
|
||||
assertEquals(compute(freq, 0.0, check), 0.0)
|
||||
assertEquals(compute(freq, 0.5, check), 0.491192)
|
||||
assertEquals(compute(freq, 0.75, check), 0.736788)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getValueUntil with boolean habit`() {
|
||||
val checks = CheckmarkList(DAILY, BOOLEAN_HABIT)
|
||||
fun getValueUntilWithBooleanHabit() {
|
||||
val checks = CheckmarkList(DAILY,
|
||||
HabitType.BOOLEAN_HABIT)
|
||||
checks.setManualCheckmarks((0..19).map {
|
||||
Checkmark(today.minus(it), CHECKED_MANUAL)
|
||||
})
|
||||
@@ -89,6 +85,7 @@ class ScoreListTest {
|
||||
Score(today.minus(17), 0.147818),
|
||||
Score(today.minus(18), 0.101148),
|
||||
Score(today.minus(19), 0.051922))
|
||||
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
}
|
||||
6
web/.babelrc
Normal file
6
web/.babelrc
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"presets": [
|
||||
["env", { "modules": false }],
|
||||
"react"
|
||||
]
|
||||
}
|
||||
26
web/Makefile
Normal file
26
web/Makefile
Normal file
@@ -0,0 +1,26 @@
|
||||
test_bundle := build/bundles/test.js
|
||||
node_modules := node_modules/.bin/mocha
|
||||
|
||||
$(node_modules):
|
||||
npm install
|
||||
|
||||
core:
|
||||
cd ../core; ./gradlew --quiet jsMainClasses jsTestClasses
|
||||
cp ../core/build/classes/kotlin/js/*/*.js node_modules/
|
||||
|
||||
$(test_bundle): test/index.js core
|
||||
mkdir -p build/bundles
|
||||
npx webpack $< --silent --mode production --output $@
|
||||
|
||||
test: $(test_bundle) $(node_modules)
|
||||
mkdir -p build/reports
|
||||
npx mocha $@ --reporter xunit > build/reports/tests.xml
|
||||
npx mocha $@
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
|
||||
distclean: clean
|
||||
rm -rf node_modules
|
||||
|
||||
.PHONY: test clean distclean core
|
||||
5530
web/package-lock.json
generated
Normal file
5530
web/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
web/package.json
Normal file
30
web/package.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "loop-habit-tracker",
|
||||
"version": "2.0.0",
|
||||
"description": "App for creating and maintaining good habits",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git@github.com:iSoron/uhabits.git"
|
||||
},
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"compile": "webpack",
|
||||
"test": "mocha"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"babel-core": "^6.26.3",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-react": "^6.24.1",
|
||||
"kotlin": "^1.3.21",
|
||||
"kotlin-test": "^1.3.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-loader": "^7.1.5",
|
||||
"mocha": "^6.1.0",
|
||||
"webpack": "^4.29.6",
|
||||
"webpack-cli": "^3.3.0"
|
||||
}
|
||||
}
|
||||
1
web/src/index.js
Normal file
1
web/src/index.js
Normal file
@@ -0,0 +1 @@
|
||||
console.log('Hello World!');
|
||||
2
web/test/index.js
Normal file
2
web/test/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
var assert = require('assert');
|
||||
var coreTest = require('core_test');
|
||||
Reference in New Issue
Block a user