Added extremely simple tests for future refactoring.
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				Solve / example-action (push) Failing after 8s
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	Solve / example-action (push) Failing after 8s
				
			This commit is contained in:
		
							parent
							
								
									80ffa962c0
								
							
						
					
					
						commit
						07e25fadd1
					
				
							
								
								
									
										2
									
								
								.github/workflows/solve.yaml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/solve.yaml
									
									
									
									
										vendored
									
									
								
							@ -15,6 +15,8 @@ jobs:
 | 
			
		||||
          distribution: 'corretto' # See 'Supported distributions' for available options
 | 
			
		||||
          java-version: '21'
 | 
			
		||||
      - uses: https://github.com/fwilhe2/setup-kotlin@main
 | 
			
		||||
      - name: Run tests
 | 
			
		||||
        run: ./simpletest.sh
 | 
			
		||||
      - name: Solutions
 | 
			
		||||
        run: |
 | 
			
		||||
          set -e
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1
									
								
								day01.kts
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										1
									
								
								day01.kts
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@ -1,3 +1,4 @@
 | 
			
		||||
#!/usr/bin/env kotlin
 | 
			
		||||
import java.io.File
 | 
			
		||||
import java.util.Scanner
 | 
			
		||||
import kotlin.math.abs
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								day01.kts.testvalue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								day01.kts.testvalue
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
			
		||||
Total distance: 1603498
 | 
			
		||||
Similarity score: 25574739
 | 
			
		||||
							
								
								
									
										1
									
								
								day02.kts
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										1
									
								
								day02.kts
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@ -1,3 +1,4 @@
 | 
			
		||||
#!/usr/bin/env kotlin
 | 
			
		||||
import java.io.File
 | 
			
		||||
import java.util.Scanner
 | 
			
		||||
import kotlin.math.abs
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								day02.kts.testvalue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								day02.kts.testvalue
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
			
		||||
Safe lines: 472
 | 
			
		||||
Safe lines with dampener: 520
 | 
			
		||||
							
								
								
									
										1
									
								
								day03.kts
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										1
									
								
								day03.kts
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							@ -1,3 +1,4 @@
 | 
			
		||||
#!/usr/bin/env kotlin
 | 
			
		||||
import java.io.File
 | 
			
		||||
import java.util.Scanner
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								day03.kts.testvalue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								day03.kts.testvalue
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
			
		||||
Part One Sum: 187833789
 | 
			
		||||
Part Two Sum: 94455185
 | 
			
		||||
							
								
								
									
										90
									
								
								simpletest.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										90
									
								
								simpletest.sh
									
									
									
									
									
										Executable file
									
								
							@ -0,0 +1,90 @@
 | 
			
		||||
#!/bin/bash
 | 
			
		||||
 | 
			
		||||
# Function to show usage
 | 
			
		||||
usage() {
 | 
			
		||||
    echo "Usage: $0 [write|validate]"
 | 
			
		||||
    exit 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Ensure a mode is provided
 | 
			
		||||
if [[ $# -ne 1 ]]; then
 | 
			
		||||
    usage
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
MODE=$1
 | 
			
		||||
 | 
			
		||||
# Write mode
 | 
			
		||||
if [[ "$MODE" == "write" ]]; then
 | 
			
		||||
    echo "Running in write mode..."
 | 
			
		||||
 | 
			
		||||
    for script in *.kts; do
 | 
			
		||||
        test_file="${script}.testvalue"
 | 
			
		||||
 | 
			
		||||
        echo "Processing $script..."
 | 
			
		||||
        output=$(kotlin "$script" 2>&1)
 | 
			
		||||
 | 
			
		||||
        if [[ -f "$test_file" ]]; then
 | 
			
		||||
            if [[ "$output" == "$(cat "$test_file")" ]]; then
 | 
			
		||||
                echo "No change: $script"
 | 
			
		||||
            else
 | 
			
		||||
                echo "Output changed for $script"
 | 
			
		||||
                diff -u "$test_file" <(echo "$output")
 | 
			
		||||
                read -p "Update test value? (y/n) " update
 | 
			
		||||
                if [[ "$update" == "y" ]]; then
 | 
			
		||||
                    echo "$output" > "$test_file"
 | 
			
		||||
                    echo "Updated $test_file"
 | 
			
		||||
                fi
 | 
			
		||||
            fi
 | 
			
		||||
        else
 | 
			
		||||
            echo "$output" > "$test_file"
 | 
			
		||||
            echo "Created $test_file"
 | 
			
		||||
        fi
 | 
			
		||||
    done
 | 
			
		||||
 | 
			
		||||
    for test_file in *.kts.testvalue; do
 | 
			
		||||
        script="${test_file%.testvalue}"
 | 
			
		||||
        if [[ ! -f "$script" ]]; then
 | 
			
		||||
            echo "Test file $test_file does not have a matching script."
 | 
			
		||||
            read -p "Delete $test_file? (y/n) " delete
 | 
			
		||||
            if [[ "$delete" == "y" ]]; then
 | 
			
		||||
                rm "$test_file"
 | 
			
		||||
                echo "Deleted $test_file"
 | 
			
		||||
            fi
 | 
			
		||||
        fi
 | 
			
		||||
    done
 | 
			
		||||
 | 
			
		||||
# Validate mode
 | 
			
		||||
elif [[ "$MODE" == "validate" ]]; then
 | 
			
		||||
    echo "Running in validate mode..."
 | 
			
		||||
    pass=0
 | 
			
		||||
    fail=0
 | 
			
		||||
 | 
			
		||||
    for test_file in *.kts.testvalue; do
 | 
			
		||||
        script="${test_file%.testvalue}"
 | 
			
		||||
        if [[ -f "$script" ]]; then
 | 
			
		||||
            output=$(kotlin "$script" 2>&1)
 | 
			
		||||
            if [[ "$output" == "$(cat "$test_file")" ]]; then
 | 
			
		||||
                echo "PASS: $script"
 | 
			
		||||
                ((pass++))
 | 
			
		||||
            else
 | 
			
		||||
                echo "FAIL: $script"
 | 
			
		||||
                diff -u "$test_file" <(echo "$output")
 | 
			
		||||
                ((fail++))
 | 
			
		||||
            fi
 | 
			
		||||
        else
 | 
			
		||||
            echo "Orphaned test file: $test_file (no matching script)"
 | 
			
		||||
            ((fail++))
 | 
			
		||||
        fi
 | 
			
		||||
    done
 | 
			
		||||
 | 
			
		||||
    echo "Summary: $pass pass, $fail fail"
 | 
			
		||||
 | 
			
		||||
    if [[ $fail -gt 0 ]]; then
 | 
			
		||||
        exit 1
 | 
			
		||||
    else
 | 
			
		||||
        exit 0
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
else
 | 
			
		||||
    usage
 | 
			
		||||
fi
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user