11package  io.github.optimumcode.json.schema.assertions.number 
22
3+ import  io.github.optimumcode.json.pointer.JsonPointer 
4+ import  io.github.optimumcode.json.schema.ErrorCollector 
5+ import  io.github.optimumcode.json.schema.ErrorCollector.Companion 
36import  io.github.optimumcode.json.schema.JsonSchema 
47import  io.github.optimumcode.json.schema.ValidationError 
58import  io.github.optimumcode.json.schema.base.KEY 
69import  io.kotest.assertions.throwables.shouldThrow 
710import  io.kotest.core.spec.style.FunSpec 
11+ import  io.kotest.core.test.TestScope 
12+ import  io.kotest.matchers.collections.shouldContainExactly 
813import  io.kotest.matchers.collections.shouldHaveSize 
914import  io.kotest.matchers.shouldBe 
1015import  kotlinx.serialization.ExperimentalSerializationApi 
@@ -110,5 +115,64 @@ class JsonSchemaMultipleOfValidationTest : FunSpec() {
110115 errors shouldHaveSize 0 
111116 }
112117 }
118+ 
119+  JsonSchema .fromDefinition(
120+  """ 
121+  { 
122+  "${KEY } schema": "http://json-schema.org/draft-07/schema#", 
123+  "multipleOf": 0.0001 
124+  } 
125+  """  .trimIndent(),
126+  ).apply  {
127+  listOf (
128+  JsonUnquotedLiteral (" 0.0075"  ),
129+  JsonUnquotedLiteral (" 0.075"  ),
130+  JsonUnquotedLiteral (" 0.75"  ),
131+  JsonUnquotedLiteral (" 7.5"  ),
132+  JsonUnquotedLiteral (" 75"  ),
133+  JsonUnquotedLiteral (" 750"  ),
134+  JsonUnquotedLiteral (" 12391239123"  ),
135+  JsonUnquotedLiteral (" -0.0075"  ),
136+  JsonUnquotedLiteral (" -0.075"  ),
137+  JsonUnquotedLiteral (" -0.75"  ),
138+  JsonUnquotedLiteral (" -7.5"  ),
139+  JsonUnquotedLiteral (" -75"  ),
140+  JsonUnquotedLiteral (" -750"  ),
141+  JsonUnquotedLiteral (" -12391239123"  ),
142+  ).forEach {
143+  test(" small number $it  is multiple of 0.0001"  ) {
144+  val  errors =  mutableListOf<ValidationError >()
145+  validate(it, errors::add) shouldBe true 
146+  errors shouldHaveSize 0 
147+  }
148+  }
149+ 
150+  listOf (
151+  JsonUnquotedLiteral (" 0.00001"  ),
152+  JsonUnquotedLiteral (" 0.00011"  ),
153+  JsonUnquotedLiteral (" 0.00751"  ),
154+  JsonUnquotedLiteral (" 0.01751"  ),
155+  JsonUnquotedLiteral (" 0.71751"  ),
156+  JsonUnquotedLiteral (" 1.71751"  ),
157+  JsonUnquotedLiteral (" -0.00001"  ),
158+  JsonUnquotedLiteral (" -0.00011"  ),
159+  JsonUnquotedLiteral (" -0.00751"  ),
160+  JsonUnquotedLiteral (" -0.01751"  ),
161+  JsonUnquotedLiteral (" -0.71751"  ),
162+  JsonUnquotedLiteral (" -1.71751"  ),
163+  ).forEach {
164+  test(" small number $it  is not a multiple of 0.0001"  ) {
165+  val  errors =  mutableListOf<ValidationError >()
166+  validate(it, errors::add) shouldBe false 
167+  errors.shouldContainExactly(
168+  ValidationError (
169+  schemaPath =  JsonPointer (" /multipleOf"  ),
170+  objectPath =  JsonPointer .ROOT ,
171+  message =  " $it  is not a multiple of 0.0001"  ,
172+  )
173+  )
174+  }
175+  }
176+  }
113177 }
114178}
0 commit comments