• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Scala-Robotics-Simulator / PPS-22-srs / #205

07 Aug 2025 03:35PM UTC coverage: 71.334% (-12.7%) from 84.0%
#205

Pull #22

github

GiuliaNardicchia
feat: implement Rand type and RandomDSL for random value generation
Pull Request #22: feat: simulation engine

58 of 225 new or added lines in 16 files covered. (25.78%)

3 existing lines in 1 file now uncovered.

647 of 907 relevant lines covered (71.33%)

10.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/scala/io/github/srs/model/ModelModule.scala
1
package io.github.srs.model
2

3
import scala.concurrent.duration.FiniteDuration
4

5
import io.github.srs.model.SimulationConfig.{ SimulationSpeed, SimulationStatus }
6
import io.github.srs.utils.random.SimpleRNG
7
import monix.eval.Task
8

9
/**
10
 * Module that defines the model logic for the Scala Robotics Simulator.
11
 */
12
object ModelModule:
13

×
14
  /**
15
   * State trait that defines the base state for the simulation.
16
   */
17
  trait State:
NEW
18

×
19
    /**
20
     * The total simulation time for the simulation.
21
     */
22
    def simulationTime: Option[FiniteDuration]
23

24
    /**
25
     * The elapsed time since the start of the simulation.
26
     */
27
    def elapsedTime: FiniteDuration
28

29
    /**
30
     * The current simulation speed.
31
     */
32
    def simulationSpeed: SimulationSpeed
33

34
    /**
35
     * The random number generator used for the simulation.
36
     */
37
    def simulationRNG: SimpleRNG
38

39
    /**
40
     * The current simulation status.
41
     */
42
    def simulationStatus: SimulationStatus
43

44
  end State
45

46
  /**
47
   * Trait representing the core model logic for updating the simulation state.
48
   *
49
   * @tparam S
50
   *   the type of the simulation state, which must extend [[State]].
51
   */
52
  trait Model[S <: State]:
53

54
    /**
55
     * Updates the state of the simulation using the provided function.
56
     * @param s
57
     *   the current state of the simulation.
58
     * @param f
59
     *   the function that takes the current state and returns a new state wrapped in a [[Task]].
60
     * @return
61
     *   the updated state wrapped in a [[Task]].
62
     */
63
    def update(s: S)(using f: S => Task[S]): Task[S]
64

65
  /**
66
   * Provider trait that defines the interface for providing a model.
67
   * @tparam S
68
   *   the type of the state, which must extend [[State]].
69
   */
70
  trait Provider[S <: State]:
71
    val model: Model[S]
72

73
  /**
74
   * Component trait that defines the interface for creating a model.
75
   *
76
   * @tparam S
77
   *   the type of the simulation state, which must extend [[State]].
78
   */
79
  trait Component[S <: State]:
80

×
81
    object Model:
NEW
82

×
83
      /**
84
       * Factory method to create a new instance of the model.
85
       *
86
       * @return
87
       *   a new instance of [[Model]].
88
       */
89
      def apply(): Model[S] = new ModelImpl
90

×
91
      /**
92
       * Private model implementation that delegates state updates to the provided function.
93
       */
94
      private class ModelImpl extends Model[S]:
95
        /**
×
96
         * @inheritdoc
97
         */
98
        override def update(s: S)(using updateLogic: S => Task[S]): Task[S] = updateLogic(s)
99
  end Component
×
100

101
  /**
102
   * Interface trait that combines the provider and component traits.
103
   * @tparam S
104
   *   the type of the state, which must extend [[State]].
105
   */
106
  trait Interface[S <: State] extends Provider[S] with Component[S]
107
end ModelModule
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc