Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 45 additions & 15 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,48 @@
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
name: Android CI

on:
pull_request:
branches: [ "master" ]

workflow_dispatch:

jobs:
Explore-GitHub-Actions:
build_and_test:
name: Build and Run Tests
runs-on: ubuntu-latest

steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v6
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Run Lint
run: ./gradlew lintDebug
continue-on-error: true

- name: Run Unit Tests and Build APK
run: ./gradlew testDebugUnitTest assembleDebug

- name: Upload Test Reports
if: always()
uses: actions/upload-artifact@v4
with:
name: unit-test-reports
path: '**/build/reports/tests/**'
retention-days: 7

- name: Upload Debug APK
uses: actions/upload-artifact@v4
with:
name: app-debug
path: '**/build/outputs/apk/debug/*.apk'
retention-days: 14
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package dev.jekis.canvacompass

import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*
import org.junit.Rule

/**
* Instrumented test, which will execute on an Android device.
Expand All @@ -15,10 +22,21 @@ import org.junit.Assert.*
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {

@get:Rule
val activityRule = ActivityScenarioRule(MainActivity::class.java)

@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("dev.jekis.canvacompass", appContext.packageName)
}
}

@Test
fun checkXmlFragmentIsDisplayed() {
onView(withId(R.id.textview_xml))
.check(matches(isDisplayed()))
onView(withText("XML Fragment"))
.check(matches(isDisplayed()))
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/dev/jekis/canvacompass/CompassUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.jekis.canvacompass

object CompassUtils {
/**
* Normalizes an angle to be within [0, 360) degrees.
*/
fun normalizeDegree(degree: Float): Float {
val normalized = degree % 360
return if (normalized < 0) normalized + 360 else normalized
}
}
26 changes: 26 additions & 0 deletions app/src/test/java/dev/jekis/canvacompass/CompassUtilsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.jekis.canvacompass

import org.junit.Assert.assertEquals
import org.junit.Test

class CompassUtilsTest {

@Test
fun `normalizeDegree should return same value if within 0 to 359`() {
assertEquals(0f, CompassUtils.normalizeDegree(0f), 0.01f)
assertEquals(180f, CompassUtils.normalizeDegree(180f), 0.01f)
assertEquals(359.9f, CompassUtils.normalizeDegree(359.9f), 0.01f)
}

@Test
fun `normalizeDegree should handle negative values`() {
assertEquals(350f, CompassUtils.normalizeDegree(-10f), 0.01f)
assertEquals(0f, CompassUtils.normalizeDegree(-360f), 0.01f)
}

@Test
fun `normalizeDegree should handle values greater than 360`() {
assertEquals(10f, CompassUtils.normalizeDegree(370f), 0.01f)
assertEquals(0f, CompassUtils.normalizeDegree(720f), 0.01f)
}
}
18 changes: 18 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. For more details, visit
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
# org.gradle.parallel=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
android.disallowKotlinSourceSets=false
android.useAndroidX=true
android.nonTransitiveRClass=true
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
9 changes: 9 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Mon Apr 20 15:45:48 MSK 2026
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=b266d5ff6b90eada6dc3b20cb090e3731302e553a27c5d3e4df1f0d76beaff06
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading