Skip to content

Commit

Permalink
Use unambiguous float32 values (Azure#516)
Browse files Browse the repository at this point in the history
* Use unambiguous float32 values

* Create funny-kings-worry.md

---------

Co-authored-by: Anton Kolesnyk <[email protected]>
  • Loading branch information
antkmsft and antkmsft authored Feb 8, 2024
1 parent 6303556 commit 8e6e124
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .changeset/funny-kings-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@azure-tools/cadl-ranch-specs": patch
"@azure-tools/cadl-ranch": patch
---

Updated expected `float32` values (42.42 and 43.43) to the values that can be exactly represented as IEEE754 (43.125 and 46.875 respectively).
28 changes: 14 additions & 14 deletions packages/cadl-ranch-specs/cadl-ranch-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -3111,7 +3111,7 @@ Expected Array input body:
Expected Array response body:

```json
[42.42]
[43.125]
```

### Type_Array_Float32Value_put
Expand All @@ -3121,7 +3121,7 @@ Expected Array response body:
Expected Array input body:

```json
[42.42]
[43.125]
```

### Type_Array_Int32Value_get
Expand Down Expand Up @@ -3311,7 +3311,7 @@ Expected dictionary input body:
Expected dictionary response body:

```json
{ "k1": 42.42 }
{ "k1": 43.125 }
```

### Type_Dictionary_Float32Value_put
Expand All @@ -3321,7 +3321,7 @@ Expected dictionary response body:
Expected dictionary input body:

```json
{ "k1": 42.42 }
{ "k1": 43.125 }
```

### Type_Dictionary_Int32Value_get
Expand Down Expand Up @@ -4173,7 +4173,7 @@ Expected input body:
Expected response body:

```json
{ "id": 42.42, "prop": 42.42 }
{ "id": 43.125, "prop": 43.125 }
```

### Type_Property_AdditionalProperties_ExtendsFloat_put
Expand All @@ -4183,7 +4183,7 @@ Expected response body:
Expected input body:

```json
{ "id": 42.42, "prop": 42.42 }
{ "id": 43.125, "prop": 43.125 }
```

### Type_Property_AdditionalProperties_ExtendsModel_get
Expand Down Expand Up @@ -4353,7 +4353,7 @@ Expected input body:
Expected response body:

```json
{ "id": 42.42, "prop": 42.42 }
{ "id": 43.125, "prop": 43.125 }
```

### Type_Property_AdditionalProperties_IsFloat_put
Expand All @@ -4363,7 +4363,7 @@ Expected response body:
Expected input body:

```json
{ "id": 42.42, "prop": 42.42 }
{ "id": 43.125, "prop": 43.125 }
```

### Type_Property_AdditionalProperties_IsModel_get
Expand Down Expand Up @@ -5599,7 +5599,7 @@ Expected input body:
Expected response body:

```json
{ "property": 42.42 }
{ "property": 43.125 }
```

### Type_Property_ValueTypes_Float_put
Expand All @@ -5609,7 +5609,7 @@ Expected response body:
Expected input body:

```json
{ "property": 42.42 }
{ "property": 43.125 }
```

### Type_Property_ValueTypes_FloatLiteral_get
Expand All @@ -5619,7 +5619,7 @@ Expected input body:
Expected response body:

```json
{ "property": 42.42 }
{ "property": 43.125 }
```

### Type_Property_ValueTypes_FloatLiteral_put
Expand All @@ -5629,7 +5629,7 @@ Expected response body:
Expected input body:

```json
{ "property": 42.42 }
{ "property": 43.125 }
```

### Type_Property_ValueTypes_Int_get
Expand Down Expand Up @@ -5759,7 +5759,7 @@ Expected input body:
Expected response body:

```json
{ "property": 43.43 }
{ "property": 46.875 }
```

### Type_Property_ValueTypes_UnionFloatLiteral_put
Expand All @@ -5769,7 +5769,7 @@ Expected response body:
Expected input body:

```json
{ "property": 43.43 }
{ "property": 46.875 }
```

### Type_Property_ValueTypes_UnionIntLiteral_get
Expand Down
2 changes: 1 addition & 1 deletion packages/cadl-ranch-specs/http/type/array/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface StringValue extends ArrayOperations<string[], "['hello', '']"> {}
@doc("Array of float values")
@route("/float32")
@operationGroup
interface Float32Value extends ArrayOperations<float32[], "[42.42]"> {}
interface Float32Value extends ArrayOperations<float32[], "[43.125]"> {}

@doc("Array of datetime values")
@route("/datetime")
Expand Down
2 changes: 1 addition & 1 deletion packages/cadl-ranch-specs/http/type/array/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const StringValueMock = createModelMockApis("string", ["hello", ""]);
Scenarios.Type_Array_StringValue_get = passOnSuccess(StringValueMock.get);
Scenarios.Type_Array_StringValue_put = passOnSuccess(StringValueMock.put);

const Float32ValueMock = createModelMockApis("float32", [42.42]);
const Float32ValueMock = createModelMockApis("float32", [43.125]);
Scenarios.Type_Array_Float32Value_get = passOnSuccess(Float32ValueMock.get);
Scenarios.Type_Array_Float32Value_put = passOnSuccess(Float32ValueMock.put);

Expand Down
2 changes: 1 addition & 1 deletion packages/cadl-ranch-specs/http/type/dictionary/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface StringValue extends DictionaryOperations<Record<string>, "{'k1': 'hell
@doc("Dictionary of float values")
@route("/float32")
@operationGroup
interface Float32Value extends DictionaryOperations<Record<float32>, "{'k1': 42.42}"> {}
interface Float32Value extends DictionaryOperations<Record<float32>, "{'k1': 43.125}"> {}

@doc("Dictionary of datetime values")
@route("/datetime")
Expand Down
2 changes: 1 addition & 1 deletion packages/cadl-ranch-specs/http/type/dictionary/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const StringValueMock = createModelMockApis("string", { k1: "hello", k2: "" });
Scenarios.Type_Dictionary_StringValue_get = passOnSuccess(StringValueMock.get);
Scenarios.Type_Dictionary_StringValue_put = passOnSuccess(StringValueMock.put);

const Float32ValueMock = createModelMockApis("float32", { k1: 42.42 });
const Float32ValueMock = createModelMockApis("float32", { k1: 43.125 });
Scenarios.Type_Dictionary_Float32Value_get = passOnSuccess(Float32ValueMock.get);
Scenarios.Type_Dictionary_Float32Value_put = passOnSuccess(Float32ValueMock.put);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ model ExtendsFloatAdditionalProperties extends Record<float32> {

@route("/extendsRecordFloat")
@operationGroup
interface ExtendsFloat extends ModelOperations<ExtendsFloatAdditionalProperties, "{'id': 42.42, 'prop': 42.42}"> {}
interface ExtendsFloat extends ModelOperations<ExtendsFloatAdditionalProperties, "{'id': 43.125, 'prop': 43.125}"> {}

#suppress "@azure-tools/typespec-azure-core/bad-record-type" "For testing"
@doc("The model is from Record<float32> type.")
Expand All @@ -220,7 +220,7 @@ model IsFloatAdditionalProperties is Record<float32> {

@route("/isRecordFloat")
@operationGroup
interface IsFloat extends ModelOperations<IsFloatAdditionalProperties, "{'id': 42.42, 'prop': 42.42}"> {}
interface IsFloat extends ModelOperations<IsFloatAdditionalProperties, "{'id': 43.125, 'prop': 43.125}"> {}

// ********************************************** Record<Model> **********************************************
@doc("model for record")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ Scenarios.Type_Property_AdditionalProperties_IsString_put = passOnSuccess(isStri

// **************************************************** Record<float32> ****************************************************
const recordFloatBody = {
id: 42.42,
prop: 42.42,
id: 43.125,
prop: 43.125,
};
const extendsFloat = createMockApis("extendsRecordFloat", recordFloatBody);
Scenarios.Type_Property_AdditionalProperties_ExtendsFloat_get = passOnSuccess(extendsFloat.get);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ interface Int extends ModelOperations<IntProperty, "42"> {}
model FloatProperty is ModelTemplate<float32>;
@route("/float")
@operationGroup
interface Float extends ModelOperations<FloatProperty, "42.42"> {}
interface Float extends ModelOperations<FloatProperty, "43.125"> {}

// Test a model with a decimal property
@doc("Model with a decimal property")
Expand Down Expand Up @@ -239,10 +239,10 @@ model IntLiteralProperty is ModelTemplate<42>;
interface IntLiteral extends ModelOperations<IntLiteralProperty, "42"> {}

@doc("Model with a float literal property.")
model FloatLiteralProperty is ModelTemplate<42.42>;
model FloatLiteralProperty is ModelTemplate<43.125>;
@route("/float/literal")
@operationGroup
interface FloatLiteral extends ModelOperations<FloatLiteralProperty, "42.42"> {}
interface FloatLiteral extends ModelOperations<FloatLiteralProperty, "43.125"> {}

@doc("Model with a boolean literal property.")
model BooleanLiteralProperty is ModelTemplate<true>;
Expand All @@ -263,7 +263,7 @@ model UnionIntLiteralProperty is ModelTemplate<42 | 43>;
interface UnionIntLiteral extends ModelOperations<UnionIntLiteralProperty, "42"> {}

@doc("Model with a union of float literal as property.")
model UnionFloatLiteralProperty is ModelTemplate<42.42 | 43.43>;
model UnionFloatLiteralProperty is ModelTemplate<43.125 | 46.875>;
@route("/union/float/literal")
@operationGroup
interface UnionFloatLiteral extends ModelOperations<UnionFloatLiteralProperty, "43.43"> {}
interface UnionFloatLiteral extends ModelOperations<UnionFloatLiteralProperty, "46.875"> {}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const intMock = createMockApis("int", 42);
Scenarios.Type_Property_ValueTypes_Int_get = passOnSuccess(intMock.get);
Scenarios.Type_Property_ValueTypes_Int_put = passOnSuccess(intMock.put);

const floatMock = createMockApis("float", 42.42);
const floatMock = createMockApis("float", 43.125);
Scenarios.Type_Property_ValueTypes_Float_get = passOnSuccess(floatMock.get);
Scenarios.Type_Property_ValueTypes_Float_put = passOnSuccess(floatMock.put);

Expand Down Expand Up @@ -124,7 +124,7 @@ const intLiteralMock = createMockApis("int/literal", 42);
Scenarios.Type_Property_ValueTypes_IntLiteral_get = passOnSuccess(intLiteralMock.get);
Scenarios.Type_Property_ValueTypes_IntLiteral_put = passOnSuccess(intLiteralMock.put);

const floatLiteralMock = createMockApis("float/literal", 42.42);
const floatLiteralMock = createMockApis("float/literal", 43.125);
Scenarios.Type_Property_ValueTypes_FloatLiteral_get = passOnSuccess(floatLiteralMock.get);
Scenarios.Type_Property_ValueTypes_FloatLiteral_put = passOnSuccess(floatLiteralMock.put);

Expand All @@ -140,6 +140,6 @@ const unionIntLiteralMock = createMockApis("union/int/literal", 42);
Scenarios.Type_Property_ValueTypes_UnionIntLiteral_get = passOnSuccess(unionIntLiteralMock.get);
Scenarios.Type_Property_ValueTypes_UnionIntLiteral_put = passOnSuccess(unionIntLiteralMock.put);

const unionFloatLiteralMock = createMockApis("union/float/literal", 43.43);
const unionFloatLiteralMock = createMockApis("union/float/literal", 46.875);
Scenarios.Type_Property_ValueTypes_UnionFloatLiteral_get = passOnSuccess(unionFloatLiteralMock.get);
Scenarios.Type_Property_ValueTypes_UnionFloatLiteral_put = passOnSuccess(unionFloatLiteralMock.put);

0 comments on commit 8e6e124

Please sign in to comment.