|
1 | 1 | module lcmtesttypes
|
2 | 2 |
|
3 |
| -export lcm_test_type_1, lcm_test_type_2, lcm_test_type_3 |
| 3 | +export lcm_test_type_1, lcm_test_type_2, lcm_test_type_3, polynomial_t, polynomial_matrix_t |
4 | 4 | export hard_coded_example
|
5 | 5 |
|
6 | 6 | using LCMCore, StaticArrays
|
@@ -133,4 +133,66 @@ function hard_coded_example(::Type{lcm_test_type_3})
|
133 | 133 | ret
|
134 | 134 | end
|
135 | 135 |
|
| 136 | +mutable struct polynomial_t <: LCMType |
| 137 | + timestamp::Int64 |
| 138 | + num_coefficients::Int32 |
| 139 | + coefficients::Vector{Float64} |
| 140 | +end |
| 141 | + |
| 142 | +@lcmtypesetup(polynomial_t, |
| 143 | + (coefficients, 1) => num_coefficients, |
| 144 | +) |
| 145 | + |
| 146 | +function Base.:(==)(x::polynomial_t, y::polynomial_t) |
| 147 | + x.timestamp == y.timestamp || return false |
| 148 | + x.num_coefficients == y.num_coefficients || return false |
| 149 | + x.coefficients == y.coefficients || return false |
| 150 | + true |
| 151 | +end |
| 152 | + |
| 153 | +function Base.rand(::Type{polynomial_t}) |
| 154 | + timestamp = rand(Int64) |
| 155 | + num_coefficients = rand(Int32(0) : Int32(10)) |
| 156 | + coefficients = rand(num_coefficients) |
| 157 | + polynomial_t(timestamp, num_coefficients, coefficients) |
| 158 | +end |
| 159 | + |
| 160 | +function hard_coded_example(::Type{polynomial_t}) |
| 161 | + polynomial_t(1234, 4, [5.0, 0.0, 1.0, 3.0]) |
| 162 | +end |
| 163 | + |
| 164 | + |
| 165 | +mutable struct polynomial_matrix_t <: LCMType |
| 166 | + timestamp::Int64 |
| 167 | + rows::Int32 |
| 168 | + cols::Int32 |
| 169 | + polynomials::Vector{Vector{polynomial_t}} |
| 170 | +end |
| 171 | + |
| 172 | +@lcmtypesetup(polynomial_matrix_t, |
| 173 | + (polynomials, 1) => rows, |
| 174 | + (polynomials, 2) => cols |
| 175 | +) |
| 176 | + |
| 177 | +function Base.:(==)(x::polynomial_matrix_t, y::polynomial_matrix_t) |
| 178 | + x.timestamp == y.timestamp || return false |
| 179 | + x.rows == y.rows || return false |
| 180 | + x.cols == y.cols || return false |
| 181 | + x.polynomials == y.polynomials || return false |
| 182 | + true |
| 183 | +end |
| 184 | + |
| 185 | +function Base.rand(::Type{polynomial_matrix_t}) |
| 186 | + timestamp = rand(Int64) |
| 187 | + rows = rand(Int32(0) : Int32(10)) |
| 188 | + cols = rand(Int32(0) : Int32(10)) |
| 189 | + polynomials = [[rand(polynomial_t) for col = 1 : cols] for row = 1 : rows] |
| 190 | + polynomial_matrix_t(timestamp, rows, cols, polynomials) |
| 191 | +end |
| 192 | + |
| 193 | +function hard_coded_example(::Type{polynomial_matrix_t}) |
| 194 | + polynomials = [[polynomial_t(1234, 4, [5.0, 0.0, 1.0, 3.0])], [polynomial_t(1234, 4, [10.0, 0.0, 2.0, 6.0])]] |
| 195 | + polynomial_matrix_t(1234, 2, 1, polynomials) |
| 196 | +end |
| 197 | + |
136 | 198 | end # module
|
0 commit comments