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

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

08 Aug 2025 08:48AM UTC coverage: 71.116% (-0.2%) from 71.35%
#221

push

github

srs-mate
chore: remove comment

650 of 914 relevant lines covered (71.12%)

10.47 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 cats.effect.IO
6
import io.github.srs.model.SimulationConfig.{ SimulationSpeed, SimulationStatus }
7
import io.github.srs.utils.random.SimpleRNG
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:
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
     *
57
     * @param s
58
     *   the current state of the simulation.
59
     * @param f
60
     *   the function that takes the current state and returns a new state wrapped in a [[IO]].
61
     * @return
62
     *   the updated state wrapped in a [[IO]].
63
     */
64
    def update(s: S)(using f: S => IO[S]): IO[S]
65

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

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

×
83
    object Model:
84

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

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

103
  /**
104
   * Interface trait that combines the provider and component traits.
105
   *
106
   * @tparam S
107
   *   the type of the state, which must extend [[State]].
108
   */
109
  trait Interface[S <: State] extends Provider[S] with Component[S]
110
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