zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

commit cf4390321f990029fd3fc99341372483624ce05b
parent 180d66c6e9c87f22ab7dcb80c9ccaf5d04d992b8
Author: sir fish <dev@srf.sh>
Date:   Thu, 17 Nov 2022 18:58:40 +0000

Merge pull request #36 from interfacerproject/alberto/decimal

Switch to using exact, arbitrary-precision floating-points
Diffstat:
Mmix.exs | 1+
Mpriv/repo/migrations/20211111090805_fill_vf_spatial_thing.exs | 6+++---
Mpriv/repo/migrations/20211111111357_fill_vf_recipe_process.exs | 2+-
Mpriv/repo/migrations/20211111114050_fill_vf_recipe_flow.exs | 4++--
Mpriv/repo/migrations/20211111191749_fill_vf_scenario_definition.exs | 2+-
Mpriv/repo/migrations/20211113071804_fill_vf_economic_resource.exs | 4++--
Mpriv/repo/migrations/20211114144908_fill_vf_economic_event.exs | 4++--
Mpriv/repo/migrations/20211114190636_fill_vf_intent.exs | 6+++---
Mpriv/repo/migrations/20211115055335_fill_vf_commitment.exs | 4++--
Mpriv/repo/migrations/20211115071129_fill_vf_fulfillment.exs | 4++--
Mpriv/repo/migrations/20211115103758_fill_vf_satisfaction.exs | 4++--
Mpriv/repo/migrations/20211115173048_fill_vf_claim.exs | 4++--
Mpriv/repo/migrations/20211115181352_fill_vf_settlement.exs | 4++--
Msrc/zenflows/vf/claim.ex | 4++--
Msrc/zenflows/vf/commitment.ex | 4++--
Msrc/zenflows/vf/duration.ex | 4++--
Msrc/zenflows/vf/duration/type.ex | 4++--
Msrc/zenflows/vf/economic_event.ex | 4++--
Msrc/zenflows/vf/economic_event/domain.ex | 44++++++++++++++++++++++----------------------
Msrc/zenflows/vf/economic_resource.ex | 8++++----
Msrc/zenflows/vf/economic_resource/query.ex | 4++--
Msrc/zenflows/vf/economic_resource/type.ex | 4++--
Msrc/zenflows/vf/fulfillment.ex | 4++--
Msrc/zenflows/vf/intent.ex | 6+++---
Msrc/zenflows/vf/measure.ex | 4++--
Msrc/zenflows/vf/measure/type.ex | 4++--
Msrc/zenflows/vf/recipe_flow.ex | 4++--
Msrc/zenflows/vf/recipe_process.ex | 4++--
Msrc/zenflows/vf/satisfaction.ex | 4++--
Msrc/zenflows/vf/scenario_definition.ex | 4++--
Msrc/zenflows/vf/settlement.ex | 4++--
Msrc/zenflows/vf/spatial_thing.ex | 12++++++------
Msrc/zenflows/vf/spatial_thing/type.ex | 18+++++++++---------
Mtest/help/factory.ex | 35+++++++++++++++++++++++++++--------
Mtest/vf/claim.test.exs | 4++--
Mtest/vf/commitment.test.exs | 28++++++++++++++--------------
Mtest/vf/duration.test.exs | 10+++++-----
Mtest/vf/economic_event.test.exs | 30+++++++++++++++---------------
Mtest/vf/economic_event/domain.test.exs | 252++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mtest/vf/economic_event/track_and_trace.test.exs | 2+-
Mtest/vf/economic_event/type.test.exs | 2+-
Mtest/vf/economic_resource/domain.test.exs | 2+-
Mtest/vf/economic_resource/track_and_trace.test.exs | 2+-
Mtest/vf/economic_resource/type.test.exs | 4++--
Mtest/vf/fulfillment.test.exs | 4++--
Mtest/vf/intent/domain.test.exs | 30+++++++++++++++---------------
Mtest/vf/intent/type.test.exs | 12++++++------
Mtest/vf/measure.test.exs | 10+++++-----
Mtest/vf/process/track_and_trace.test.exs | 2+-
Mtest/vf/recipe_flow/domain.test.exs | 28++++++++++++++--------------
Mtest/vf/recipe_flow/type.test.exs | 8++++----
Mtest/vf/recipe_process/domain.test.exs | 2+-
Mtest/vf/recipe_process/type.test.exs | 5++---
Mtest/vf/satisfaction.test.exs | 4++--
Mtest/vf/scenario_definition/type.test.exs | 4++--
Mtest/vf/settlement.test.exs | 4++--
Mtest/vf/spatial_thing/domain.test.exs | 24++++++++++++------------
Mtest/vf/spatial_thing/type.test.exs | 12++++++------
58 files changed, 368 insertions(+), 349 deletions(-)

diff --git a/mix.exs b/mix.exs @@ -57,6 +57,7 @@ defp deps() do # db {:ecto_sql, "~> 3.9"}, {:postgrex, ">= 0.0.0"}, + {:decimal, "~> 2.0"}, # crypto {:plug_crypto, "~> 1.2"}, diff --git a/priv/repo/migrations/20211111090805_fill_vf_spatial_thing.exs b/priv/repo/migrations/20211111090805_fill_vf_spatial_thing.exs @@ -23,9 +23,9 @@ def change() do add :name, :text, null: false add :note, :text add :mappable_address, :text - add :lat, :float - add :long, :float - add :alt, :float + add :lat, :decimal + add :long, :decimal + add :alt, :decimal timestamps() end end diff --git a/priv/repo/migrations/20211111111357_fill_vf_recipe_process.exs b/priv/repo/migrations/20211111111357_fill_vf_recipe_process.exs @@ -31,7 +31,7 @@ def change() do add :process_conforms_to_id, references("vf_process_specification"), null: false add :process_classified_as, {:array, :text} add :has_duration_unit_type, :vf_time_unit - add :has_duration_numeric_duration, :float + add :has_duration_numeric_duration, :decimal timestamps() end diff --git a/priv/repo/migrations/20211111114050_fill_vf_recipe_flow.exs b/priv/repo/migrations/20211111114050_fill_vf_recipe_flow.exs @@ -43,9 +43,9 @@ def change() do add :recipe_clause_of_id, references("vf_recipe_exchange") add :recipe_flow_resource_id, references("vf_recipe_resource"), null: false add :resource_quantity_has_unit_id, references("vf_unit") - add :resource_quantity_has_numerical_value, :float + add :resource_quantity_has_numerical_value, :decimal add :effort_quantity_has_unit_id, references("vf_unit") - add :effort_quantity_has_numerical_value, :float + add :effort_quantity_has_numerical_value, :decimal timestamps() end diff --git a/priv/repo/migrations/20211111191749_fill_vf_scenario_definition.exs b/priv/repo/migrations/20211111191749_fill_vf_scenario_definition.exs @@ -29,7 +29,7 @@ def change() do add :name, :text, null: false add :note, :text add :has_duration_unit_type, :vf_time_unit - add :has_duration_numeric_duration, :float + add :has_duration_numeric_duration, :decimal timestamps() end diff --git a/priv/repo/migrations/20211113071804_fill_vf_economic_resource.exs b/priv/repo/migrations/20211113071804_fill_vf_economic_resource.exs @@ -26,9 +26,9 @@ def change() do add :classified_as, {:array, :text} add :conforms_to_id, references("vf_resource_specification"), null: false add :accounting_quantity_has_unit_id, references("vf_unit"), null: false - add :accounting_quantity_has_numerical_value, :float, null: false + add :accounting_quantity_has_numerical_value, :decimal, null: false add :onhand_quantity_has_unit_id, references("vf_unit"), null: false - add :onhand_quantity_has_numerical_value, :float, nulL: false + add :onhand_quantity_has_numerical_value, :decimal, nulL: false add :primary_accountable_id, references("vf_agent"), null: false add :custodian_id, references("vf_agent"), null: false add :stage_id, references("vf_process_specification") diff --git a/priv/repo/migrations/20211114144908_fill_vf_economic_event.exs b/priv/repo/migrations/20211114144908_fill_vf_economic_event.exs @@ -30,9 +30,9 @@ def change() do add :resource_classified_as, {:array, :text} add :resource_conforms_to_id, references("vf_resource_specification") add :resource_quantity_has_unit_id, references("vf_unit") - add :resource_quantity_has_numerical_value, :float + add :resource_quantity_has_numerical_value, :decimal add :effort_quantity_has_unit_id, references("vf_unit") - add :effort_quantity_has_numerical_value, :float + add :effort_quantity_has_numerical_value, :decimal add :has_beginning, :timestamptz add :has_end, :timestamptz add :has_point_in_time, :timestamptz diff --git a/priv/repo/migrations/20211114190636_fill_vf_intent.exs b/priv/repo/migrations/20211114190636_fill_vf_intent.exs @@ -30,11 +30,11 @@ def change() do add :resource_conforms_to_id, references("vf_resource_specification") add :resource_inventoried_as_id, references("vf_economic_resource") add :resource_quantity_has_unit_id, references("vf_unit") - add :resource_quantity_has_numerical_value, :float + add :resource_quantity_has_numerical_value, :decimal add :effort_quantity_has_unit_id, references("vf_unit") - add :effort_quantity_has_numerical_value, :float + add :effort_quantity_has_numerical_value, :decimal add :available_quantity_has_unit_id, references("vf_unit") - add :available_quantity_has_numerical_value, :float + add :available_quantity_has_numerical_value, :decimal add :at_location_id, references("vf_spatial_thing") add :has_beginning, :timestamptz add :has_end, :timestamptz diff --git a/priv/repo/migrations/20211115055335_fill_vf_commitment.exs b/priv/repo/migrations/20211115055335_fill_vf_commitment.exs @@ -29,9 +29,9 @@ def change() do add :resource_conforms_to_id, references("vf_resource_specification") add :resource_inventoried_as_id, references("vf_economic_resource") add :resource_quantity_has_unit_id, references("vf_unit") - add :resource_quantity_has_numerical_value, :float + add :resource_quantity_has_numerical_value, :decimal add :effort_quantity_has_unit_id, references("vf_unit") - add :effort_quantity_has_numerical_value, :float + add :effort_quantity_has_numerical_value, :decimal add :has_beginning, :timestamptz add :has_end, :timestamptz add :has_point_in_time, :timestamptz diff --git a/priv/repo/migrations/20211115071129_fill_vf_fulfillment.exs b/priv/repo/migrations/20211115071129_fill_vf_fulfillment.exs @@ -23,9 +23,9 @@ def change() do add :fulfilled_by_id, references("vf_economic_event"), null: false add :fulfills_id, references("vf_commitment"), null: false add :resource_quantity_has_unit_id, references("vf_unit") - add :resource_quantity_has_numerical_value, :float + add :resource_quantity_has_numerical_value, :decimal add :effort_quantity_has_unit_id, references("vf_unit") - add :effort_quantity_has_numerical_value, :float + add :effort_quantity_has_numerical_value, :decimal add :note, :text timestamps() end diff --git a/priv/repo/migrations/20211115103758_fill_vf_satisfaction.exs b/priv/repo/migrations/20211115103758_fill_vf_satisfaction.exs @@ -23,9 +23,9 @@ def change() do add :satisfies_id, references("vf_intent"), null: false add :satisfied_by_id, references("vf_event_or_commitment"), null: false add :resource_quantity_has_unit_id, references("vf_unit") - add :resource_quantity_has_numerical_value, :float + add :resource_quantity_has_numerical_value, :decimal add :effort_quantity_has_unit_id, references("vf_unit") - add :effort_quantity_has_numerical_value, :float + add :effort_quantity_has_numerical_value, :decimal add :note, :text timestamps() end diff --git a/priv/repo/migrations/20211115173048_fill_vf_claim.exs b/priv/repo/migrations/20211115173048_fill_vf_claim.exs @@ -26,9 +26,9 @@ def change() do add :resource_classified_as, {:array, :text} add :resource_conforms_to_id, references("vf_resource_specification") add :resource_quantity_has_unit_id, references("vf_unit") - add :resource_quantity_has_numerical_value, :float + add :resource_quantity_has_numerical_value, :decimal add :effort_quantity_has_unit_id, references("vf_unit") - add :effort_quantity_has_numerical_value, :float + add :effort_quantity_has_numerical_value, :decimal add :triggered_by_id, references("vf_economic_event") add :due, :timestamptz add :created, :timestamptz diff --git a/priv/repo/migrations/20211115181352_fill_vf_settlement.exs b/priv/repo/migrations/20211115181352_fill_vf_settlement.exs @@ -23,9 +23,9 @@ def change() do add :settled_by_id, references("vf_economic_event"), null: false add :settles_id, references("vf_claim"), null: false add :resource_quantity_has_unit_id, references("vf_unit") - add :resource_quantity_has_numerical_value, :float + add :resource_quantity_has_numerical_value, :decimal add :effort_quantity_has_unit_id, references("vf_unit") - add :effort_quantity_has_numerical_value, :float + add :effort_quantity_has_numerical_value, :decimal add :note, :text timestamps() end diff --git a/src/zenflows/vf/claim.ex b/src/zenflows/vf/claim.ex @@ -59,10 +59,10 @@ schema "vf_claim" do belongs_to :resource_conforms_to, ResourceSpecification field :resource_quantity, :map, virtual: true belongs_to :resource_quantity_has_unit, Unit - field :resource_quantity_has_numerical_value, :float + field :resource_quantity_has_numerical_value, :decimal field :effort_quantity, :map, virtual: true belongs_to :effort_quantity_has_unit, Unit - field :effort_quantity_has_numerical_value, :float + field :effort_quantity_has_numerical_value, :decimal belongs_to :triggered_by, EconomicEvent field :due, :utc_datetime_usec field :finished, :boolean diff --git a/src/zenflows/vf/commitment.ex b/src/zenflows/vf/commitment.ex @@ -74,10 +74,10 @@ schema "vf_commitment" do belongs_to :resource_inventoried_as, EconomicResource field :resource_quantity, :map, virtual: true belongs_to :resource_quantity_has_unit, Unit - field :resource_quantity_has_numerical_value, :float + field :resource_quantity_has_numerical_value, :decimal field :effort_quantity, :map, virtual: true belongs_to :effort_quantity_has_unit, Unit - field :effort_quantity_has_numerical_value, :float + field :effort_quantity_has_numerical_value, :decimal field :has_beginning, :utc_datetime_usec field :has_end, :utc_datetime_usec field :has_point_in_time, :utc_datetime_usec diff --git a/src/zenflows/vf/duration.ex b/src/zenflows/vf/duration.ex @@ -28,13 +28,13 @@ alias Zenflows.VF.TimeUnitEnum @type t() :: %__MODULE__{ unit_type: TimeUnitEnum.t(), - numeric_duration: float(), + numeric_duration: Decimal.t(), } @primary_key false embedded_schema do field :unit_type, TimeUnitEnum - field :numeric_duration, :float + field :numeric_duration, :decimal end @doc """ diff --git a/src/zenflows/vf/duration/type.ex b/src/zenflows/vf/duration/type.ex @@ -28,7 +28,7 @@ A number representing the duration, will be paired with a unit. @desc "A `Duration` represents an interval between two `DateTime` values." object :duration do @desc @numeric_duration - field :numeric_duration, non_null(:float) + field :numeric_duration, non_null(:decimal) @desc @unit_type field :unit_type, non_null(:time_unit) @@ -37,7 +37,7 @@ end @desc "Mutation input structure for defining time durations." input_object :iduration, name: "IDuration" do @desc @numeric_duration - field :numeric_duration, non_null(:float) + field :numeric_duration, non_null(:decimal) @desc @unit_type field :unit_type, non_null(:time_unit) diff --git a/src/zenflows/vf/economic_event.ex b/src/zenflows/vf/economic_event.ex @@ -77,10 +77,10 @@ schema "vf_economic_event" do belongs_to :resource_conforms_to, ResourceSpecification field :resource_quantity, :map, virtual: true belongs_to :resource_quantity_has_unit, Unit - field :resource_quantity_has_numerical_value, :float + field :resource_quantity_has_numerical_value, :decimal field :effort_quantity, :map, virtual: true belongs_to :effort_quantity_has_unit, Unit - field :effort_quantity_has_numerical_value, :float + field :effort_quantity_has_numerical_value, :decimal field :has_beginning, :utc_datetime_usec field :has_end, :utc_datetime_usec field :has_point_in_time, :utc_datetime_usec diff --git a/src/zenflows/vf/economic_event/domain.ex b/src/zenflows/vf/economic_event/domain.ex @@ -257,8 +257,8 @@ defp handle_insert(key, %{action_id: action_id} = evt, _) where(EconomicResource, id: ^evt.resource_inventoried_as_id), set: [previous_event_id: evt.id], inc: [ - accounting_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, - onhand_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, + accounting_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), + onhand_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), ]) end defp handle_insert(key, %{action_id: action_id} = evt, _) @@ -514,7 +514,7 @@ defp handle_insert(key, %{action_id: "accept"} = evt, _) do evt.resource_quantity_has_numerical_value != res.onhand_quantity_has_numerical_value -> {:error, "the accept events need to fully accept the resource"} - res.container? and res.onhand_quantity_has_numerical_value <= 0 -> + res.container? and not Decimal.gt?(res.onhand_quantity_has_numerical_value, 0) -> {:error, "the accept events need container resources to have positive onhand quantity"} any_combine_separate?.() -> @@ -534,7 +534,7 @@ defp handle_insert(key, %{action_id: "accept"} = evt, _) do where(EconomicResource, id: ^evt.resource_inventoried_as_id), set: [previous_event_id: evt.id], inc: [ - onhand_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, + onhand_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), ]) end defp handle_insert(key, %{action_id: "modify"} = evt, _) do @@ -639,7 +639,7 @@ defp handle_insert(key, %{action_id: "transferCustody"} = evt, res_params) do {:error, "you can't transfer-custody a contained resource"} evt.resource_quantity_has_unit_id != res.onhand_quantity_has_unit_id -> {:error, "the unit of resource-quantity must match with the unit of resource-inventoried-as"} - res.container? and res.onhand_quantity_has_numerical_value <= 0 -> + res.container? and not Decimal.gt?(res.onhand_quantity_has_numerical_value, 0) -> {:error, "the transfer-custody events need container resources to have positive onhand-quantity"} res.container? && evt.resource_quantity_has_numerical_value != res.onhand_quantity_has_numerical_value -> {:error, "the transfer-custody events need to fully transfer the resource"} @@ -667,7 +667,7 @@ defp handle_insert(key, %{action_id: "transferCustody"} = evt, res_params) do where(EconomicResource, id: ^evt.resource_inventoried_as_id), set: [previous_event_id: evt.id], inc: [ - onhand_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, + onhand_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), ]) |> Multi.update_all("#{key}.inc", where(EconomicResource, id: ^evt.to_resource_inventoried_as_id), inc: [ onhand_quantity_has_numerical_value: evt.resource_quantity_has_numerical_value, @@ -704,7 +704,7 @@ defp handle_insert(key, %{action_id: "transferCustody"} = evt, res_params) do where(EconomicResource, id: ^evt.resource_inventoried_as_id), set: [previous_event_id: evt.id], inc: [ - onhand_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, + onhand_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), ]) |> Multi.merge(fn %{^key => evt} -> if res.container? do @@ -764,7 +764,7 @@ defp handle_insert(key, %{action_id: "transferAllRights"} = evt, res_params) do {:error, "you can't transfer-all-rights a contained resource"} evt.resource_quantity_has_unit_id != res.accounting_quantity_has_unit_id -> {:error, "the unit of resource-quantity must match with the unit of resource-inventoried-as"} - res.container? and res.accounting_quantity_has_numerical_value <= 0 -> + res.container? and not Decimal.gt?(res.accounting_quantity_has_numerical_value, 0) -> {:error, "the transfer-all-rights events need container resources to have positive accounting-quantity"} res.container? && evt.resource_quantity_has_numerical_value != res.accounting_quantity_has_numerical_value -> {:error, "the transfer-all-rights events need to fully transfer the resource"} @@ -792,7 +792,7 @@ defp handle_insert(key, %{action_id: "transferAllRights"} = evt, res_params) do where(EconomicResource, id: ^evt.resource_inventoried_as_id), set: [previous_event_id: evt.id], inc: [ - accounting_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, + accounting_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), ]) |> Multi.update_all(:inc, where(EconomicResource, id: ^evt.to_resource_inventoried_as_id), inc: [ accounting_quantity_has_numerical_value: evt.resource_quantity_has_numerical_value, @@ -828,7 +828,7 @@ defp handle_insert(key, %{action_id: "transferAllRights"} = evt, res_params) do where(EconomicResource, id: ^evt.resource_inventoried_as_id), set: [previous_event_id: evt.id], inc: [ - accounting_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, + accounting_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), ]) |> Multi.merge(fn %{^key => evt} -> if res.container? do @@ -890,9 +890,9 @@ defp handle_insert(key, %{action_id: "transfer"} = evt, res_params) do {:error, "you can't transfer a contained resource"} evt.resource_quantity_has_unit_id != res.accounting_quantity_has_unit_id -> {:error, "the unit of resource-quantity must match with the unit of resource-inventoried-as"} - res.container? and res.accounting_quantity_has_numerical_value <= 0 -> + res.container? and not Decimal.gt?(res.accounting_quantity_has_numerical_value, 0) -> {:error, "the transfer events need container resources to have positive accounting-quantity"} - res.container? and res.onhand_quantity_has_numerical_value <= 0 -> + res.container? and not Decimal.gt?(res.onhand_quantity_has_numerical_value, 0) -> {:error, "the transfer events need container resources to have positive onhand-quantity"} res.container? && evt.resource_quantity_has_numerical_value != res.accounting_quantity_has_numerical_value -> {:error, "the transfer events need to fully transfer the resource"} @@ -922,8 +922,8 @@ defp handle_insert(key, %{action_id: "transfer"} = evt, res_params) do where(EconomicResource, id: ^evt.resource_inventoried_as_id), set: [previous_event_id: evt.id], inc: [ - accounting_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, - onhand_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, + accounting_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), + onhand_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), ]) |> Multi.update_all("#{key}.inc", where(EconomicResource, id: ^evt.to_resource_inventoried_as_id), inc: [ accounting_quantity_has_numerical_value: evt.resource_quantity_has_numerical_value, @@ -961,8 +961,8 @@ defp handle_insert(key, %{action_id: "transfer"} = evt, res_params) do where(EconomicResource, id: ^evt.resource_inventoried_as_id), set: [previous_event_id: evt.id], inc: [ - accounting_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, - onhand_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, + accounting_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), + onhand_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), ]) |> Multi.merge(fn %{^key => evt} -> if res.container? do @@ -1025,9 +1025,9 @@ defp handle_insert(key, %{action_id: "move"} = evt, res_params) do {:error, "you can't move a contained resource"} evt.resource_quantity_has_unit_id != res.accounting_quantity_has_unit_id -> {:error, "the unit of resource-quantity must match with the unit of resource-inventoried-as"} - res.container? and res.accounting_quantity_has_numerical_value <= 0 -> + res.container? and not Decimal.gt?(res.accounting_quantity_has_numerical_value, 0) -> {:error, "the move events need container resources to have positive accounting-quantity"} - res.container? and res.onhand_quantity_has_numerical_value <= 0 -> + res.container? and not Decimal.gt?(res.onhand_quantity_has_numerical_value, 0) -> {:error, "the move events need container resources to have positive onhand-quantity"} res.container? && evt.resource_quantity_has_numerical_value != res.accounting_quantity_has_numerical_value -> {:error, "the move events need to fully move the resource"} @@ -1061,8 +1061,8 @@ defp handle_insert(key, %{action_id: "move"} = evt, res_params) do where(EconomicResource, id: ^evt.resource_inventoried_as_id), set: [previous_event_id: evt.id], inc: [ - accounting_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, - onhand_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, + accounting_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), + onhand_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), ]) |> Multi.update_all("#{key}.inc", where(EconomicResource, id: ^evt.to_resource_inventoried_as_id), inc: [ accounting_quantity_has_numerical_value: evt.resource_quantity_has_numerical_value, @@ -1100,8 +1100,8 @@ defp handle_insert(key, %{action_id: "move"} = evt, res_params) do where(EconomicResource, id: ^evt.resource_inventoried_as_id), set: [previous_event_id: evt.id], inc: [ - accounting_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, - onhand_quantity_has_numerical_value: -evt.resource_quantity_has_numerical_value, + accounting_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), + onhand_quantity_has_numerical_value: Decimal.negate(evt.resource_quantity_has_numerical_value), ]) |> Multi.merge(fn %{^key => evt} -> if res.container? do diff --git a/src/zenflows/vf/economic_resource.ex b/src/zenflows/vf/economic_resource.ex @@ -45,10 +45,10 @@ alias Zenflows.VF.{ conforms_to: ResourceSpecification.t(), accounting_quantity: Measure.t() | nil, accounting_quantity_has_unit: Unit.t(), - accounting_quantity_has_numerical_value: float(), + accounting_quantity_has_numerical_value: Decimal.t(), onhand_quantity: Measure.t() | nil, onhand_quantity_has_unit: Unit.t(), - onhand_quantity_has_numerical_value: float(), + onhand_quantity_has_numerical_value: Decimal.t(), primary_accountable: Agent.t(), custodian: Agent.t(), stage: ProcessSpecification.t() | nil, @@ -76,10 +76,10 @@ schema "vf_economic_resource" do belongs_to :conforms_to, ResourceSpecification field :accounting_quantity, :map, virtual: true belongs_to :accounting_quantity_has_unit, Unit - field :accounting_quantity_has_numerical_value, :float + field :accounting_quantity_has_numerical_value, :decimal field :onhand_quantity, :map, virtual: true belongs_to :onhand_quantity_has_unit, Unit - field :onhand_quantity_has_numerical_value, :float + field :onhand_quantity_has_numerical_value, :decimal belongs_to :primary_accountable, Agent belongs_to :custodian, Agent belongs_to :stage, ProcessSpecification diff --git a/src/zenflows/vf/economic_resource/query.ex b/src/zenflows/vf/economic_resource/query.ex @@ -74,8 +74,8 @@ defp all_validate(params) do or_custodian: {:array, ID}, conforms_to: {:array, ID}, or_conforms_to: {:array, ID}, - gt_onhand_quantity_has_numerical_value: :float, - or_gt_onhand_quantity_has_numerical_value: :float, + gt_onhand_quantity_has_numerical_value: :decimal, + or_gt_onhand_quantity_has_numerical_value: :decimal, name: :string, or_name: :string, note: :string, diff --git a/src/zenflows/vf/economic_resource/type.ex b/src/zenflows/vf/economic_resource/type.ex @@ -250,8 +250,8 @@ input_object :economic_resource_filter_params do field :or_primary_accountable, list_of(non_null(:id)) field :custodian, list_of(non_null(:id)) field :or_custodian, list_of(non_null(:id)) - field :gt_onhand_quantity_has_numerical_value, :float - field :or_gt_onhand_quantity_has_numerical_value, :float + field :gt_onhand_quantity_has_numerical_value, :decimal + field :or_gt_onhand_quantity_has_numerical_value, :decimal field :name, :string field :or_name, :string field :note, :string diff --git a/src/zenflows/vf/fulfillment.ex b/src/zenflows/vf/fulfillment.ex @@ -46,10 +46,10 @@ schema "vf_fulfillment" do belongs_to :fulfills, Commitment field :resource_quantity, :map, virtual: true belongs_to :resource_quantity_has_unit, Unit - field :resource_quantity_has_numerical_value, :float + field :resource_quantity_has_numerical_value, :decimal field :effort_quantity, :map, virtual: true belongs_to :effort_quantity_has_unit, Unit - field :effort_quantity_has_numerical_value, :float + field :effort_quantity_has_numerical_value, :decimal timestamps() end diff --git a/src/zenflows/vf/intent.ex b/src/zenflows/vf/intent.ex @@ -77,13 +77,13 @@ schema "vf_intent" do belongs_to :resource_inventoried_as, EconomicResource field :resource_quantity, :map, virtual: true belongs_to :resource_quantity_has_unit, Unit - field :resource_quantity_has_numerical_value, :float + field :resource_quantity_has_numerical_value, :decimal field :effort_quantity, :map, virtual: true belongs_to :effort_quantity_has_unit, Unit - field :effort_quantity_has_numerical_value, :float + field :effort_quantity_has_numerical_value, :decimal field :available_quantity, :map, virtual: true belongs_to :available_quantity_has_unit, Unit - field :available_quantity_has_numerical_value, :float + field :available_quantity_has_numerical_value, :decimal belongs_to :at_location, SpatialThing field :has_beginning, :utc_datetime_usec field :has_end, :utc_datetime_usec diff --git a/src/zenflows/vf/measure.ex b/src/zenflows/vf/measure.ex @@ -29,13 +29,13 @@ alias Zenflows.VF.Unit @type t() :: %__MODULE__{ has_unit_id: Zenflows.DB.ID.t(), - has_numerical_value: float(), + has_numerical_value: Decimal.t(), } @primary_key false embedded_schema do belongs_to :has_unit, Unit - field :has_numerical_value, :float + field :has_numerical_value, :decimal end @doc """ diff --git a/src/zenflows/vf/measure/type.ex b/src/zenflows/vf/measure/type.ex @@ -33,7 +33,7 @@ unit. See http://www.qudt.org/pages/QUDToverviewPage.html . """ object :measure do @desc @has_numerical_value - field :has_numerical_value, non_null(:float) + field :has_numerical_value, non_null(:decimal) @desc @has_unit field :has_unit, :unit, resolve: &Resolv.has_unit/3 @@ -45,7 +45,7 @@ if not present, rather than empty. """ input_object :imeasure, name: "IMeasure" do @desc @has_numerical_value - field :has_numerical_value, non_null(:float) + field :has_numerical_value, non_null(:decimal) @desc "(`Unit`) " <> @has_unit field :has_unit_id, :id, name: "has_unit" diff --git a/src/zenflows/vf/recipe_flow.ex b/src/zenflows/vf/recipe_flow.ex @@ -53,10 +53,10 @@ schema "vf_recipe_flow" do belongs_to :recipe_flow_resource, RecipeResource field :resource_quantity, :map, virtual: true belongs_to :resource_quantity_has_unit, Unit - field :resource_quantity_has_numerical_value, :float + field :resource_quantity_has_numerical_value, :decimal field :effort_quantity, :map, virtual: true belongs_to :effort_quantity_has_unit, Unit - field :effort_quantity_has_numerical_value, :float + field :effort_quantity_has_numerical_value, :decimal belongs_to :recipe_clause_of, RecipeExchange timestamps() end diff --git a/src/zenflows/vf/recipe_process.ex b/src/zenflows/vf/recipe_process.ex @@ -37,7 +37,7 @@ alias Zenflows.VF.{ process_classified_as: [String.t()] | nil, has_duration: Duration.t() | nil, has_duration_unit_type: TimeUnitEnum.t() | nil, - has_duration_numeric_duration: float() | nil, + has_duration_numeric_duration: Decimal.t() | nil, } schema "vf_recipe_process" do @@ -47,7 +47,7 @@ schema "vf_recipe_process" do field :process_classified_as, {:array, :string} field :has_duration, :map, virtual: true field :has_duration_unit_type, TimeUnitEnum - field :has_duration_numeric_duration, :float + field :has_duration_numeric_duration, :decimal timestamps() end diff --git a/src/zenflows/vf/satisfaction.ex b/src/zenflows/vf/satisfaction.ex @@ -45,10 +45,10 @@ schema "vf_satisfaction" do belongs_to :satisfies, Intent field :resource_quantity, :map, virtual: true belongs_to :resource_quantity_has_unit, Unit - field :resource_quantity_has_numerical_value, :float + field :resource_quantity_has_numerical_value, :decimal field :effort_quantity, :map, virtual: true belongs_to :effort_quantity_has_unit, Unit - field :effort_quantity_has_numerical_value, :float + field :effort_quantity_has_numerical_value, :decimal field :note, :string timestamps() end diff --git a/src/zenflows/vf/scenario_definition.ex b/src/zenflows/vf/scenario_definition.ex @@ -33,7 +33,7 @@ alias Zenflows.VF.{ name: String.t(), note: String.t() | nil, has_duration_unit_type: TimeUnitEnum.t() | nil, - has_duration_numeric_duration: float() | nil, + has_duration_numeric_duration: Decimal.t() | nil, has_duration: Duration.t() | nil, } @@ -42,7 +42,7 @@ schema "vf_scenario_definition" do field :note, :string field :has_duration, :map, virtual: true field :has_duration_unit_type, TimeUnitEnum - field :has_duration_numeric_duration, :float + field :has_duration_numeric_duration, :decimal timestamps() end diff --git a/src/zenflows/vf/settlement.ex b/src/zenflows/vf/settlement.ex @@ -45,10 +45,10 @@ schema "vf_settlement" do belongs_to :settles, Claim field :resource_quantity, :map, virtual: true belongs_to :resource_quantity_has_unit, Unit - field :resource_quantity_has_numerical_value, :float + field :resource_quantity_has_numerical_value, :decimal field :effort_quantity, :map, virtual: true belongs_to :effort_quantity_has_unit, Unit - field :effort_quantity_has_numerical_value, :float + field :effort_quantity_has_numerical_value, :decimal field :note, :string timestamps() end diff --git a/src/zenflows/vf/spatial_thing.ex b/src/zenflows/vf/spatial_thing.ex @@ -29,9 +29,9 @@ alias Zenflows.DB.{Schema, Validate} id: String.t(), name: String.t(), mappable_address: String.t() | nil, - lat: float() | nil, - long: float() | nil, - alt: float() | nil, + lat: Decimal.t() | nil, + long: Decimal.t() | nil, + alt: Decimal.t() | nil, note: String.t() | nil, } @@ -41,9 +41,9 @@ alias Zenflows.DB.{Schema, Validate} schema "vf_spatial_thing" do field :name, :string field :mappable_address, :string - field :lat, :float - field :long, :float - field :alt, :float + field :lat, :decimal + field :long, :decimal + field :alt, :decimal field :note, :string timestamps() end diff --git a/src/zenflows/vf/spatial_thing/type.ex b/src/zenflows/vf/spatial_thing/type.ex @@ -46,13 +46,13 @@ object :spatial_thing do field :mappable_address, :string @desc @lat - field :lat, :float + field :lat, :decimal @desc @long - field :long, :float + field :long, :decimal @desc @alt - field :alt, :float + field :alt, :decimal @desc @note field :note, :string @@ -66,13 +66,13 @@ input_object :spatial_thing_create_params do field :mappable_address, :string @desc @lat - field :lat, :float + field :lat, :decimal @desc @long - field :long, :float + field :long, :decimal @desc @alt - field :alt, :float + field :alt, :decimal @desc @note field :note, :string @@ -88,13 +88,13 @@ input_object :spatial_thing_update_params do field :mappable_address, :string @desc @lat - field :lat, :float + field :lat, :decimal @desc @long - field :long, :float + field :long, :decimal @desc @alt - field :alt, :float + field :alt, :decimal @desc @note field :note, :string diff --git a/test/help/factory.ex b/test/help/factory.ex @@ -65,14 +65,33 @@ def int(max \\ 100) do end @doc """ -Returns a random float of the from 0 (inclusive) and 1 (exclusive) -multiplied by `mul`. +Returns a random float between 0 (inclusive) and 1 (exclusive) +multiplied by `mul`, which is 100 by default. """ @spec float() :: float() def float(mul \\ 100) do :rand.uniform() * mul end +@doc """ +Returns a string that represents a `t:Decimal.t()` between 0 +(inclusive) and 1 (exclusive) multiplied by `mul`, which is 100 by +default. +""" +@spec decimal() :: String.t() +def decimal(mul \\ 100) do + to_string(decimald(mul)) +end + +@doc """ +Returns a `t:Decimal.t()` between 0 (inclusive) and 1 (exclusive) +multiplied by `mul`, which is 100 by default. +""" +@spec decimald() :: Decimal.t() +def decimald(mul \\ 100) do + Decimal.from_float(float(mul)) +end + @doc "Returns a random boolean." @spec bool() :: boolean() def bool() do @@ -138,7 +157,7 @@ end def build(:iduration) do %{ unit_type: build(:time_unit), - numeric_duration: float(), + numeric_duration: decimald(), } end @@ -152,7 +171,7 @@ end def build(:imeasure) do %VF.Measure{ has_unit: build(:unit), - has_numerical_value: float(), + has_numerical_value: decimald(), } end @@ -160,9 +179,9 @@ def build(:spatial_thing) do %VF.SpatialThing{ name: str("some name"), mappable_address: str("some mappable_address"), - lat: float(), - long: float(), - alt: float(), + lat: decimald(), + long: decimald(), + alt: decimald(), note: str("some note"), } end @@ -550,7 +569,7 @@ def insert_economic_event!() do resource_classified_as: str_list("some uri"), resource_conforms_to_id: insert!(:resource_specification).id, resource_quantity: %{ - has_numerical_value: float(), + has_numerical_value: decimald(), has_unit_id: insert!(:unit).id, }, has_point_in_time: now(), diff --git a/test/vf/claim.test.exs b/test/vf/claim.test.exs @@ -29,11 +29,11 @@ setup do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, effort_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, triggered_by_id: Factory.insert!(:economic_event).id, due: Factory.now(), diff --git a/test/vf/commitment.test.exs b/test/vf/commitment.test.exs @@ -31,11 +31,11 @@ setup do resource_classified_as: Factory.str_list("uri"), resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, effort_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, resource_inventoried_as_id: Factory.insert!(:economic_resource).id, resource_conforms_to_id: Factory.insert!(:resource_specification).id, @@ -102,9 +102,9 @@ describe "create Commitment" do assert comm.resource_conforms_to_id == params.resource_conforms_to_id assert comm.resource_inventoried_as_id == nil assert comm.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert comm.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(comm.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert comm.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert comm.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(comm.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) assert comm.has_beginning == nil assert comm.has_end == nil assert comm.has_point_in_time == params.has_point_in_time @@ -138,9 +138,9 @@ describe "create Commitment" do assert comm.resource_conforms_to_id == params.resource_conforms_to_id assert comm.resource_inventoried_as_id == nil assert comm.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert comm.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(comm.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert comm.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert comm.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(comm.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) assert comm.has_beginning == params.has_beginning assert comm.has_end == nil assert comm.has_point_in_time == nil @@ -174,9 +174,9 @@ describe "create Commitment" do assert comm.resource_conforms_to_id == params.resource_conforms_to_id assert comm.resource_inventoried_as_id == nil assert comm.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert comm.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(comm.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert comm.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert comm.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(comm.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) assert comm.has_beginning == nil assert comm.has_end == params.has_end assert comm.has_point_in_time == nil @@ -209,9 +209,9 @@ describe "create Commitment" do assert comm.resource_conforms_to_id == params.resource_conforms_to_id assert comm.resource_inventoried_as_id == nil assert comm.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert comm.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(comm.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert comm.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert comm.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(comm.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) assert comm.has_beginning == params.has_beginning assert comm.has_end == params.has_end assert comm.has_point_in_time == nil @@ -256,9 +256,9 @@ describe "create Commitment" do assert comm.resource_conforms_to_id == params.resource_conforms_to_id assert comm.resource_inventoried_as_id == nil assert comm.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert comm.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(comm.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert comm.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert comm.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(comm.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) assert comm.has_beginning == params.has_beginning assert comm.has_end == params.has_end assert comm.has_point_in_time == nil @@ -291,9 +291,9 @@ describe "create Commitment" do assert comm.resource_conforms_to_id == nil assert comm.resource_inventoried_as_id == params.resource_inventoried_as_id assert comm.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert comm.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(comm.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert comm.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert comm.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(comm.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) assert comm.has_beginning == params.has_beginning assert comm.has_end == params.has_end assert comm.has_point_in_time == nil diff --git a/test/vf/duration.test.exs b/test/vf/duration.test.exs @@ -29,7 +29,7 @@ alias Zenflows.VF.{Duration, TimeUnit} embedded_schema do field :has_duration, :map, virtual: true field :has_duration_unit_type, TimeUnit - field :has_duration_numeric_duration, :float + field :has_duration_numeric_duration, :decimal end def changeset(params) do @@ -55,11 +55,11 @@ setup do %{ params: %{ unit_type: Factory.build(:time_unit), - numeric_duration: Factory.float(), + numeric_duration: Factory.decimal(), }, inserted: %Dummy{ has_duration_unit_type: Factory.build(:time_unit), - has_duration_numeric_duration: Factory.float(), + has_duration_numeric_duration: Factory.decimal(), }, } end @@ -76,7 +76,7 @@ test "insert", %{params: params} do # fields are properly set when `:has_duration` is properly set assert %Changeset{valid?: true, changes: chgs} = Dummy.changeset(%{has_duration: params}) assert chgs.has_duration_unit_type == params.unit_type - assert chgs.has_duration_numeric_duration == params.numeric_duration + assert Decimal.eq?(chgs.has_duration_numeric_duration, params.numeric_duration) # when no fields are provided, no fields are set assert %Changeset{valid?: false, changes: chgs, errors: errs} @@ -123,7 +123,7 @@ test "update", %{params: params, inserted: schema} do # since ecto won't change it if it is already there if schema.has_duration_unit_type != params.unit_type, do: assert chgs.has_duration_unit_type == params.unit_type - assert chgs.has_duration_numeric_duration == params.numeric_duration + assert Decimal.eq?(chgs.has_duration_numeric_duration, params.numeric_duration) # when no fields are provided, no fields are set assert %Changeset{valid?: false, changes: chgs, errors: errs} diff --git a/test/vf/economic_event.test.exs b/test/vf/economic_event.test.exs @@ -86,7 +86,7 @@ describe "`chgset/1` with raise:" do receiver_id: agent.id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_point_in_time: DateTime.utc_now(), }} @@ -168,7 +168,7 @@ describe "`chgset/1` with produce:" do receiver_id: agent.id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_beginning: DateTime.utc_now(), }} @@ -250,7 +250,7 @@ describe "`chgset/1` with lower:" do resource_inventoried_as_id: Factory.insert!(:economic_resource).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: DateTime.utc_now(), }} @@ -295,7 +295,7 @@ describe "`chgset/1` with consume:" do resource_inventoried_as_id: Factory.insert!(:economic_resource).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_beginning: DateTime.utc_now(), has_end: DateTime.utc_now(), @@ -338,7 +338,7 @@ describe "`chgset/1` with use:" do receiver_id: Factory.insert!(:agent).id, effort_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_point_in_time: DateTime.utc_now(), }} @@ -394,7 +394,7 @@ test "`chgset/1` with work: pass when all good" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, effort_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_beginning: DateTime.utc_now(), }) @@ -409,7 +409,7 @@ describe "`chgset/1` with cite:" do receiver_id: Factory.insert!(:agent).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: DateTime.utc_now(), }} @@ -513,7 +513,7 @@ describe "`chgset/1` with pickup:" do resource_inventoried_as_id: Factory.insert!(:economic_resource).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_point_in_time: DateTime.utc_now(), }} @@ -558,7 +558,7 @@ describe "`chgset/1` with dropoff:" do resource_inventoried_as_id: Factory.insert!(:economic_resource).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, to_location_id: Factory.insert!(:spatial_thing).id, has_beginning: DateTime.utc_now(), @@ -604,7 +604,7 @@ describe "`chgset/1` with accept:" do resource_inventoried_as_id: Factory.insert!(:economic_resource).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: DateTime.utc_now(), }} @@ -649,7 +649,7 @@ describe "`chgset/1` with modify:" do resource_inventoried_as_id: Factory.insert!(:economic_resource).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_beginning: DateTime.utc_now(), has_end: DateTime.utc_now(), @@ -691,7 +691,7 @@ test "`chgset/1` with transferCustody: pass when all good" do resource_inventoried_as_id: Factory.insert!(:economic_resource).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_beginning: DateTime.utc_now(), }) @@ -705,7 +705,7 @@ test "`chgset/1` with transferAllRights: pass when all good" do resource_inventoried_as_id: Factory.insert!(:economic_resource).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, to_location_id: Factory.insert!(:spatial_thing).id, has_end: DateTime.utc_now(), @@ -720,7 +720,7 @@ test "`chgset/1` with transfer: pass when all good" do resource_inventoried_as_id: Factory.insert!(:economic_resource).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, to_location_id: Factory.insert!(:spatial_thing).id, has_beginning: DateTime.utc_now(), @@ -738,7 +738,7 @@ describe "`chgset/1` with move:" do resource_inventoried_as_id: Factory.insert!(:economic_resource).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_point_in_time: DateTime.utc_now(), }} diff --git a/test/vf/economic_event/domain.test.exs b/test/vf/economic_event/domain.test.exs @@ -41,7 +41,7 @@ setup ctx do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -58,7 +58,7 @@ setup ctx do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -98,7 +98,7 @@ describe "`create/2` with raise:" do resource_inventoried_as_id: res.id, resource_quantity: %{ has_unit_id: res.accounting_quantity_has_unit_id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_point_in_time: Factory.now(), }} @@ -115,7 +115,7 @@ describe "`create/2` with raise:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), to_location_id: Factory.insert!(:spatial_thing).id, @@ -152,9 +152,9 @@ describe "`create/2` with raise:" do assert res.primary_accountable_id == evt_params.receiver_id assert res.custodian_id == evt_params.receiver_id - assert res.accounting_quantity_has_numerical_value == evt_params.resource_quantity.has_numerical_value + assert Decimal.eq?(res.accounting_quantity_has_numerical_value, evt_params.resource_quantity.has_numerical_value) assert res.accounting_quantity_has_unit_id == evt_params.resource_quantity.has_unit_id - assert res.onhand_quantity_has_numerical_value == evt_params.resource_quantity.has_numerical_value + assert Decimal.eq?(res.onhand_quantity_has_numerical_value, evt_params.resource_quantity.has_numerical_value) assert res.onhand_quantity_has_unit_id == evt_params.resource_quantity.has_unit_id assert res.current_location_id == evt_params.to_location_id end @@ -164,10 +164,10 @@ describe "`create/2` with raise:" do assert {:ok, %EconomicEvent{}} = Domain.create(params) res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value + params.resource_quantity.has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value + params.resource_quantity.has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + Decimal.add(res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + Decimal.add(res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) end test "fail when the agent doesn't have ownership over the resource", %{params: params} do @@ -211,7 +211,7 @@ describe "`create/2` with produce:" do resource_inventoried_as_id: res.id, resource_quantity: %{ has_unit_id: res.accounting_quantity_has_unit_id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_beginning: Factory.now(), }} @@ -229,7 +229,7 @@ describe "`create/2` with produce:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), to_location_id: Factory.insert!(:spatial_thing).id, @@ -266,9 +266,9 @@ describe "`create/2` with produce:" do assert res.primary_accountable_id == evt_params.receiver_id assert res.custodian_id == evt_params.receiver_id - assert res.accounting_quantity_has_numerical_value == evt_params.resource_quantity.has_numerical_value + assert Decimal.eq?(res.accounting_quantity_has_numerical_value, evt_params.resource_quantity.has_numerical_value) assert res.accounting_quantity_has_unit_id == evt_params.resource_quantity.has_unit_id - assert res.onhand_quantity_has_numerical_value == evt_params.resource_quantity.has_numerical_value + assert Decimal.eq?(res.onhand_quantity_has_numerical_value, evt_params.resource_quantity.has_numerical_value) assert res.onhand_quantity_has_unit_id == evt_params.resource_quantity.has_unit_id assert res.current_location_id == evt_params.to_location_id end @@ -278,10 +278,10 @@ describe "`create/2` with produce:" do assert {:ok, %EconomicEvent{}} = Domain.create(params) res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value + params.resource_quantity.has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value + params.resource_quantity.has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + Decimal.add(res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + Decimal.add(res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) end test "fail when the agent doesn't have ownership over the resource", %{params: params} do @@ -320,7 +320,7 @@ describe "`create/2` with lower:" do resource_inventoried_as_id: res.id, resource_quantity: %{ has_unit_id: res.accounting_quantity_has_unit_id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), }} @@ -330,10 +330,10 @@ describe "`create/2` with lower:" do res_before = EconomicResource.Domain.one!(params.resource_inventoried_as_id) assert {:ok, %EconomicEvent{}} = Domain.create(params) res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value - params.resource_quantity.has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value - params.resource_quantity.has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + Decimal.sub(res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + Decimal.sub(res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) end test "fail when the agent doesn't have ownership over the resource", %{params: params} do @@ -373,7 +373,7 @@ describe "`create/2` with consume:" do resource_inventoried_as_id: res.id, resource_quantity: %{ has_unit_id: res.accounting_quantity_has_unit_id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_beginning: Factory.now(), has_end: Factory.now(), @@ -385,10 +385,10 @@ describe "`create/2` with consume:" do assert {:ok, %EconomicEvent{}} = Domain.create(params) res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value - params.resource_quantity.has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value - params.resource_quantity.has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + Decimal.sub(res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + Decimal.sub(res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) end test "fail when the agent doesn't have ownership over the resource", %{params: params} do @@ -428,11 +428,11 @@ describe "`create/2` with use:" do resource_inventoried_as_id: res.id, resource_quantity: %{ has_unit_id: res.accounting_quantity_has_unit_id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, effort_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_point_in_time: Factory.now(), }} @@ -502,7 +502,7 @@ describe "`create/2` with pickup:" do end test "fail when event's quantity value and resource's onhand-quantity value differ", %{params: params} do - params = update_in(params.resource_quantity.has_numerical_value, &(&1 + 1)) + params = update_in(params.resource_quantity.has_numerical_value, &Decimal.add(&1, 1)) assert {:error, "the pickup events need to fully pickup the resource"} = Domain.create(params) end @@ -571,7 +571,7 @@ describe "`create/2` with dropoff:" do @tag :want_container test "fail when the resource is a container and event's quantity value and resource's onhand-quantity value differ", %{params: params} do - params = update_in(params.resource_quantity.has_numerical_value, &(&1 + 1)) + params = update_in(params.resource_quantity.has_numerical_value, &Decimal.add(&1, 1)) assert {:error, "the dropoff events need to fully dropoff the resource"} = Domain.create(params) end @@ -604,10 +604,10 @@ describe "`create/2` with accept:" do assert {:ok, %EconomicEvent{}} = Domain.create(params) res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value - params.resource_quantity.has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + res_before.accounting_quantity_has_numerical_value) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + Decimal.sub(res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) end test "fail when provider doesn't have custody over the resource", %{params: params} do @@ -633,7 +633,7 @@ describe "`create/2` with accept:" do end test "fail when event's quantity value and resource's onhand-quantity value differ", %{params: params} do - params = update_in(params.resource_quantity.has_numerical_value, &(&1 + 1)) + params = update_in(params.resource_quantity.has_numerical_value, &Decimal.add(&1, 1)) assert {:error, "the accept events need to fully accept the resource"} = Domain.create(params) end @@ -702,10 +702,10 @@ describe "`create/2` with modify:" do res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) proc = Process.Domain.one!(params.output_of_id) assert res_after.stage_id == proc.based_on_id - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value + params.resource_quantity.has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + res_before.accounting_quantity_has_numerical_value) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + Decimal.add(res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) end test "fail when provider doesn't have custody over the resource", %{params: params} do @@ -727,7 +727,7 @@ describe "`create/2` with modify:" do end test "fail when event's quantity value and resource's onhand-quantity value differ", %{params: params} do - params = update_in(params.resource_quantity.has_numerical_value, &(&1 + 1)) + params = update_in(params.resource_quantity.has_numerical_value, &Decimal.add(&1, 1)) assert {:error, "the modify events need to fully modify the resource"} = Domain.create(params) end @@ -754,7 +754,7 @@ describe "`create/2` with transferCustody:" do resource_conforms_to_id: res.conforms_to_id, resource_quantity: %{ has_unit_id: res.accounting_quantity_has_unit_id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_point_in_time: Factory.now(), } @@ -801,7 +801,7 @@ describe "`create/2` with transferCustody:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -834,10 +834,10 @@ describe "`create/2` with transferCustody:" do to_res = evt.to_resource_inventoried_as res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value - params.resource_quantity.has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + res_before.accounting_quantity_has_numerical_value) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + Decimal.sub(res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) assert to_res.name == res_params.name assert to_res.note == res_params.note @@ -853,9 +853,9 @@ describe "`create/2` with transferCustody:" do assert to_res.primary_accountable_id == params.receiver_id assert to_res.custodian_id == params.receiver_id - assert to_res.accounting_quantity_has_numerical_value == 0 + assert Decimal.eq?(to_res.accounting_quantity_has_numerical_value, 0) assert to_res.accounting_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert to_res.onhand_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(to_res.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert to_res.onhand_quantity_has_unit_id == params.resource_quantity.has_unit_id assert to_res.current_location_id == params.to_location_id @@ -878,15 +878,15 @@ describe "`create/2` with transferCustody:" do res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) to_res_after = EconomicResource.Domain.one!(params.to_resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value - params.resource_quantity.has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + res_before.accounting_quantity_has_numerical_value) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + Decimal.sub(res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) - assert to_res_after.accounting_quantity_has_numerical_value == - to_res_before.accounting_quantity_has_numerical_value - assert to_res_after.onhand_quantity_has_numerical_value == - to_res_before.onhand_quantity_has_numerical_value + params.resource_quantity.has_numerical_value + assert Decimal.eq?(to_res_after.accounting_quantity_has_numerical_value, + to_res_before.accounting_quantity_has_numerical_value) + assert Decimal.eq?(to_res_after.onhand_quantity_has_numerical_value, + Decimal.add(to_res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) end test "fail when provider doesn't have custody over the resource", %{params: params} do @@ -925,7 +925,7 @@ describe "`create/2` with transferCustody:" do @tag :want_container test "fail when event's quantity value and resource's onhand-quantity value differ", %{params: params} do - params = update_in(params.resource_quantity.has_numerical_value, &(&1 + 1)) + params = update_in(params.resource_quantity.has_numerical_value, &Decimal.add(&1, 1)) assert {:error, "the transfer-custody events need to fully transfer the resource"} = Domain.create(params) end @@ -947,7 +947,7 @@ describe "`create/2` with transferCustody:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -973,7 +973,7 @@ describe "`create/2` with transferCustody:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -1021,7 +1021,7 @@ describe "`create/2` with transferAllRights:" do resource_conforms_to_id: res.conforms_to_id, resource_quantity: %{ has_unit_id: res.accounting_quantity_has_unit_id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_point_in_time: Factory.now(), } @@ -1067,7 +1067,7 @@ describe "`create/2` with transferAllRights:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -1100,10 +1100,10 @@ describe "`create/2` with transferAllRights:" do to_res = evt.to_resource_inventoried_as res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value - params.resource_quantity.has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + Decimal.sub(res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + res_before.onhand_quantity_has_numerical_value) assert to_res.name == res_params.name assert to_res.note == res_params.note @@ -1119,9 +1119,9 @@ describe "`create/2` with transferAllRights:" do assert to_res.primary_accountable_id == params.receiver_id assert to_res.custodian_id == params.receiver_id - assert to_res.accounting_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(to_res.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert to_res.accounting_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert to_res.onhand_quantity_has_numerical_value == 0 + assert Decimal.eq?(to_res.onhand_quantity_has_numerical_value, 0) assert to_res.onhand_quantity_has_unit_id == params.resource_quantity.has_unit_id from(r in EconomicResource, @@ -1143,15 +1143,15 @@ describe "`create/2` with transferAllRights:" do res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) to_res_after = EconomicResource.Domain.one!(params.to_resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value - params.resource_quantity.has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + Decimal.sub(res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + res_before.onhand_quantity_has_numerical_value) - assert to_res_after.accounting_quantity_has_numerical_value == - to_res_before.accounting_quantity_has_numerical_value + params.resource_quantity.has_numerical_value - assert to_res_after.onhand_quantity_has_numerical_value == - to_res_before.onhand_quantity_has_numerical_value + assert Decimal.eq?(to_res_after.accounting_quantity_has_numerical_value, + Decimal.add(to_res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(to_res_after.onhand_quantity_has_numerical_value, + to_res_before.onhand_quantity_has_numerical_value) end test "fail when provider doesn't have accountability over the resource", %{params: params} do @@ -1181,16 +1181,16 @@ describe "`create/2` with transferAllRights:" do err = "the transfer-all-rights events need container resources to have positive accounting-quantity" res = EconomicResource.Domain.one!(params.resource_inventoried_as_id) - Changeset.change(res, accounting_quantity_has_numerical_value: 0.0) |> Repo.update!() + Changeset.change(res, accounting_quantity_has_numerical_value: Decimal.new(0)) |> Repo.update!() assert {:error, ^err} = Domain.create(params) - Changeset.change(res, accounting_quantity_has_numerical_value: -1.0) |> Repo.update!() + Changeset.change(res, accounting_quantity_has_numerical_value: Decimal.new(-1)) |> Repo.update!() assert {:error, ^err} = Domain.create(params) end @tag :want_container test "fail when event's quantity value and resource's accounting-quantity value differ", %{params: params} do - params = update_in(params.resource_quantity.has_numerical_value, &(&1 + 1)) + params = update_in(params.resource_quantity.has_numerical_value, &Decimal.add(&1, 1)) assert {:error, "the transfer-all-rights events need to fully transfer the resource"} = Domain.create(params) end @@ -1212,7 +1212,7 @@ describe "`create/2` with transferAllRights:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -1238,7 +1238,7 @@ describe "`create/2` with transferAllRights:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -1286,7 +1286,7 @@ describe "`create/2` with transfer:" do resource_conforms_to_id: res.conforms_to_id, resource_quantity: %{ has_unit_id: res.accounting_quantity_has_unit_id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_point_in_time: Factory.now(), } @@ -1332,7 +1332,7 @@ describe "`create/2` with transfer:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -1367,10 +1367,10 @@ describe "`create/2` with transfer:" do to_res = evt.to_resource_inventoried_as res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value - params.resource_quantity.has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value - params.resource_quantity.has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + Decimal.sub(res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + Decimal.sub(res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) assert to_res.name == res_params.name assert to_res.note == res_params.note @@ -1386,9 +1386,9 @@ describe "`create/2` with transfer:" do assert to_res.primary_accountable_id == params.receiver_id assert to_res.custodian_id == params.receiver_id - assert to_res.accounting_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(to_res.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert to_res.accounting_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert to_res.onhand_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(to_res.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert to_res.onhand_quantity_has_unit_id == params.resource_quantity.has_unit_id from(r in EconomicResource, @@ -1411,15 +1411,15 @@ describe "`create/2` with transfer:" do res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) to_res_after = EconomicResource.Domain.one!(params.to_resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value - params.resource_quantity.has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value - params.resource_quantity.has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + Decimal.sub(res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + Decimal.sub(res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) - assert to_res_after.accounting_quantity_has_numerical_value == - to_res_before.accounting_quantity_has_numerical_value + params.resource_quantity.has_numerical_value - assert to_res_after.onhand_quantity_has_numerical_value == - to_res_before.onhand_quantity_has_numerical_value + params.resource_quantity.has_numerical_value + assert Decimal.eq?(to_res_after.accounting_quantity_has_numerical_value, + Decimal.add(to_res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(to_res_after.onhand_quantity_has_numerical_value, + Decimal.add(to_res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) end test "fail when provider doesn't have accountability over the resource", %{params: params} do @@ -1467,11 +1467,11 @@ describe "`create/2` with transfer:" do err = "the transfer events need container resources to have positive accounting-quantity" res = EconomicResource.Domain.one!(params.resource_inventoried_as_id) - Changeset.change(res, accounting_quantity_has_numerical_value: 0.0) + Changeset.change(res, accounting_quantity_has_numerical_value: Decimal.new(0)) |> Repo.update!() assert {:error, ^err} = Domain.create(params) - Changeset.change(res, accounting_quantity_has_numerical_value: -1.0) |> Repo.update!() + Changeset.change(res, accounting_quantity_has_numerical_value: Decimal.new(-1)) |> Repo.update!() assert {:error, ^err} = Domain.create(params) end @@ -1480,11 +1480,11 @@ describe "`create/2` with transfer:" do err = "the transfer events need container resources to have positive onhand-quantity" res = EconomicResource.Domain.one!(params.resource_inventoried_as_id) - Changeset.change(res, onhand_quantity_has_numerical_value: 0.0) + Changeset.change(res, onhand_quantity_has_numerical_value: Decimal.new(0)) |> Repo.update!() assert {:error, ^err} = Domain.create(params) - Changeset.change(res, onhand_quantity_has_numerical_value: -1.0) + Changeset.change(res, onhand_quantity_has_numerical_value: Decimal.new(-1)) |> Repo.update!() assert {:error, ^err} = Domain.create(params) end @@ -1492,7 +1492,7 @@ describe "`create/2` with transfer:" do @tag :want_container test "fail when event's quantity value and resource's accounting-quantity value differ", %{params: params} do EconomicResource.Domain.one!(params.resource_inventoried_as_id) - |> Changeset.change(accounting_quantity_has_numerical_value: params.resource_quantity.has_numerical_value + 1) + |> Changeset.change(accounting_quantity_has_numerical_value: Decimal.add(params.resource_quantity.has_numerical_value, 1)) |> Repo.update!() assert {:error, "the transfer events need to fully transfer the resource"} = @@ -1502,7 +1502,7 @@ describe "`create/2` with transfer:" do @tag :want_container test "fail when event's quantity value and resource's onhnad-quantity value differ", %{params: params} do EconomicResource.Domain.one!(params.resource_inventoried_as_id) - |> Changeset.change(onhand_quantity_has_numerical_value: params.resource_quantity.has_numerical_value + 1) + |> Changeset.change(onhand_quantity_has_numerical_value: Decimal.add(params.resource_quantity.has_numerical_value, 1)) |> Repo.update!() assert {:error, "the transfer events need to fully transfer the resource"} = Domain.create(params) @@ -1525,7 +1525,7 @@ describe "`create/2` with transfer:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -1551,7 +1551,7 @@ describe "`create/2` with transfer:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -1588,7 +1588,7 @@ describe "`create/2` with move:" do resource_conforms_to_id: res.conforms_to_id, resource_quantity: %{ has_unit_id: res.accounting_quantity_has_unit_id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_point_in_time: Factory.now(), } @@ -1634,7 +1634,7 @@ describe "`create/2` with move:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -1667,10 +1667,10 @@ describe "`create/2` with move:" do to_res = evt.to_resource_inventoried_as res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value - params.resource_quantity.has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value - params.resource_quantity.has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + Decimal.sub(res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + Decimal.sub(res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) assert to_res.name == res_params.name assert to_res.note == res_params.note @@ -1686,9 +1686,9 @@ describe "`create/2` with move:" do assert to_res.primary_accountable_id == params.receiver_id assert to_res.custodian_id == params.receiver_id - assert to_res.accounting_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(to_res.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert to_res.accounting_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert to_res.onhand_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(to_res.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert to_res.onhand_quantity_has_unit_id == params.resource_quantity.has_unit_id from(r in EconomicResource, @@ -1711,15 +1711,15 @@ describe "`create/2` with move:" do res_after = EconomicResource.Domain.one!(params.resource_inventoried_as_id) to_res_after = EconomicResource.Domain.one!(params.to_resource_inventoried_as_id) - assert res_after.accounting_quantity_has_numerical_value == - res_before.accounting_quantity_has_numerical_value - params.resource_quantity.has_numerical_value - assert res_after.onhand_quantity_has_numerical_value == - res_before.onhand_quantity_has_numerical_value - params.resource_quantity.has_numerical_value + assert Decimal.eq?(res_after.accounting_quantity_has_numerical_value, + Decimal.sub(res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(res_after.onhand_quantity_has_numerical_value, + Decimal.sub(res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) - assert to_res_after.accounting_quantity_has_numerical_value == - to_res_before.accounting_quantity_has_numerical_value + params.resource_quantity.has_numerical_value - assert to_res_after.onhand_quantity_has_numerical_value == - to_res_before.onhand_quantity_has_numerical_value + params.resource_quantity.has_numerical_value + assert Decimal.eq?(to_res_after.accounting_quantity_has_numerical_value, + Decimal.add(to_res_before.accounting_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) + assert Decimal.eq?(to_res_after.onhand_quantity_has_numerical_value, + Decimal.add(to_res_before.onhand_quantity_has_numerical_value, params.resource_quantity.has_numerical_value)) end test "fail when provider doesn't have accountability over the resource", %{params: params} do @@ -1809,7 +1809,7 @@ describe "`create/2` with move:" do @tag :want_container test "fail when event's quantity value and resource's accounting-quantity value differ", %{params: params} do EconomicResource.Domain.one!(params.resource_inventoried_as_id) - |> Changeset.change(accounting_quantity_has_numerical_value: params.resource_quantity.has_numerical_value + 1) + |> Changeset.change(accounting_quantity_has_numerical_value: Decimal.add(params.resource_quantity.has_numerical_value, 1)) |> Repo.update!() assert {:error, "the move events need to fully move the resource"} = @@ -1819,7 +1819,7 @@ describe "`create/2` with move:" do @tag :want_container test "fail when event's quantity value and resource's onhnad-quantity value differ", %{params: params} do EconomicResource.Domain.one!(params.resource_inventoried_as_id) - |> Changeset.change(onhand_quantity_has_numerical_value: params.resource_quantity.has_numerical_value + 1) + |> Changeset.change(onhand_quantity_has_numerical_value: Decimal.add(params.resource_quantity.has_numerical_value, 1)) |> Repo.update!() assert {:error, "the move events need to fully move the resource"} = @@ -1843,7 +1843,7 @@ describe "`create/2` with move:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } @@ -1869,7 +1869,7 @@ describe "`create/2` with move:" do resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_end: Factory.now(), } diff --git a/test/vf/economic_event/track_and_trace.test.exs b/test/vf/economic_event/track_and_trace.test.exs @@ -110,7 +110,7 @@ test "previous/2 works" do has_unit_id: unit.id, }, effort_quantity: %{ - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), has_unit_id: Factory.insert!(:unit).id, }, has_point_in_time: Factory.now(), diff --git a/test/vf/economic_event/type.test.exs b/test/vf/economic_event/type.test.exs @@ -27,7 +27,7 @@ setup do receiver_id: agent_id, resource_conforms_to_id: Factory.insert!(:resource_specification).id, resource_quantity_has_unit_id: Factory.insert!(:unit).id, - resource_quantity_has_numerical_value: Factory.float(), + resource_quantity_has_numerical_value: Factory.decimal(), has_end: DateTime.utc_now(), }, inserted: %{}, diff --git a/test/vf/economic_resource/domain.test.exs b/test/vf/economic_resource/domain.test.exs @@ -33,7 +33,7 @@ alias Zenflows.VF.{ setup ctx do %{id: unit_id} = Factory.insert!(:unit) - num_val = Factory.float() + num_val = Factory.decimal() params = %{ name: Factory.str("name"), note: Factory.str("note"), diff --git a/test/vf/economic_resource/track_and_trace.test.exs b/test/vf/economic_resource/track_and_trace.test.exs @@ -99,7 +99,7 @@ test "previous/2 works" do has_unit_id: unit.id, }, effort_quantity: %{ - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), has_unit_id: Factory.insert!(:unit).id, }, has_point_in_time: Factory.now(), diff --git a/test/vf/economic_resource/type.test.exs b/test/vf/economic_resource/type.test.exs @@ -81,9 +81,9 @@ describe "Query" do assert data["classifiedAs"] == new.classified_as assert data["conformsTo"]["id"] == new.conforms_to_id assert data["accountingQuantity"]["hasUnit"]["id"] == new.accounting_quantity_has_unit_id - assert data["accountingQuantity"]["hasNumericalValue"] == new.accounting_quantity_has_numerical_value + assert Decimal.eq?(data["accountingQuantity"]["hasNumericalValue"], new.accounting_quantity_has_numerical_value) assert data["onhandQuantity"]["hasUnit"]["id"] == new.onhand_quantity_has_unit_id - assert data["onhandQuantity"]["hasNumericalValue"] == new.onhand_quantity_has_numerical_value + assert Decimal.eq?(data["onhandQuantity"]["hasNumericalValue"], new.onhand_quantity_has_numerical_value) assert data["primaryAccountable"]["id"] == new.primary_accountable_id assert data["custodian"]["id"] == new.custodian_id assert data["stage"]["id"] == new.stage_id diff --git a/test/vf/fulfillment.test.exs b/test/vf/fulfillment.test.exs @@ -27,11 +27,11 @@ setup do fulfills_id: Factory.insert!(:commitment).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, effort_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, }} end diff --git a/test/vf/intent/domain.test.exs b/test/vf/intent/domain.test.exs @@ -44,15 +44,15 @@ setup do resource_classified_as: Factory.str_list("uri"), resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, effort_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, available_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, has_beginning: Factory.now(), has_end: Factory.now(), @@ -95,11 +95,11 @@ describe "create/1" do assert Map.take(int, keys) == Map.take(params, keys) assert int.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert int.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(int.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert int.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert int.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(int.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) assert int.available_quantity_has_unit_id == params.available_quantity.has_unit_id - assert int.available_quantity_has_numerical_value == params.available_quantity.has_numerical_value + assert Decimal.eq?(int.available_quantity_has_numerical_value, params.available_quantity.has_numerical_value) end test "with good params (with only :receiver): creates an Intent", %{params: params} do @@ -117,11 +117,11 @@ describe "create/1" do assert Map.take(int, keys) == Map.take(params, keys) assert int.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert int.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(int.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert int.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert int.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(int.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) assert int.available_quantity_has_unit_id == params.available_quantity.has_unit_id - assert int.available_quantity_has_numerical_value == params.available_quantity.has_numerical_value + assert Decimal.eq?(int.available_quantity_has_numerical_value, params.available_quantity.has_numerical_value) end test "with bad params (with both :provider and :receiver): doesn't create an Intent", %{params: params} do @@ -152,11 +152,11 @@ describe "update/2" do assert Map.take(new, keys) == Map.take(params, keys) assert new.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert new.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(new.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert new.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert new.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(new.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) assert new.available_quantity_has_unit_id == params.available_quantity.has_unit_id - assert new.available_quantity_has_numerical_value == params.available_quantity.has_numerical_value + assert Decimal.eq?(new.available_quantity_has_numerical_value, params.available_quantity.has_numerical_value) end test "with good params (with only :receiver): updates the Intent", %{params: params} do @@ -175,11 +175,11 @@ describe "update/2" do assert Map.take(new, keys) == Map.take(params, keys) assert new.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert new.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(new.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert new.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert new.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(new.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) assert new.available_quantity_has_unit_id == params.available_quantity.has_unit_id - assert new.available_quantity_has_numerical_value == params.available_quantity.has_numerical_value + assert Decimal.eq?(new.available_quantity_has_numerical_value, params.available_quantity.has_numerical_value) end test "with bad params (with both :provider and :receiver): updates the Intent", %{params: params} do diff --git a/test/vf/intent/type.test.exs b/test/vf/intent/type.test.exs @@ -33,15 +33,15 @@ setup do "resourceClassifiedAs" => Factory.str_list("uri"), "resourceQuantity" => %{ "hasUnit" => Factory.insert!(:unit).id, - "hasNumericalValue" => Factory.float(), + "hasNumericalValue" => Factory.decimal(), }, "effortQuantity" => %{ "hasUnit" => Factory.insert!(:unit).id, - "hasNumericalValue" => Factory.float(), + "hasNumericalValue" => Factory.decimal(), }, "availableQuantity" => %{ "hasUnit" => Factory.insert!(:unit).id, - "hasNumericalValue" => Factory.float(), + "hasNumericalValue" => Factory.decimal(), }, "hasBeginning" => Factory.iso_now(), "hasEnd" => Factory.iso_now(), @@ -109,11 +109,11 @@ describe "Query" do assert data["resourceInventoriedAs"]["id"] == int.resource_inventoried_as_id assert data["resourceConformsTo"]["id"] == int.resource_conforms_to_id assert data["resourceClassifiedAs"] == int.resource_classified_as - assert data["resourceQuantity"]["hasNumericalValue"] == int.resource_quantity_has_numerical_value + assert Decimal.eq?(data["resourceQuantity"]["hasNumericalValue"], int.resource_quantity_has_numerical_value) assert data["resourceQuantity"]["hasUnit"]["id"] == int.resource_quantity_has_unit_id - assert data["effortQuantity"]["hasNumericalValue"] == int.effort_quantity_has_numerical_value + assert Decimal.eq?(data["effortQuantity"]["hasNumericalValue"], int.effort_quantity_has_numerical_value) assert data["effortQuantity"]["hasUnit"]["id"] == int.effort_quantity_has_unit_id - assert data["availableQuantity"]["hasNumericalValue"] == int.available_quantity_has_numerical_value + assert Decimal.eq?(data["availableQuantity"]["hasNumericalValue"], int.available_quantity_has_numerical_value) assert data["availableQuantity"]["hasUnit"]["id"] == int.available_quantity_has_unit_id assert data["hasBeginning"] == DateTime.to_iso8601(int.has_beginning) assert data["hasEnd"] == DateTime.to_iso8601(int.has_end) diff --git a/test/vf/measure.test.exs b/test/vf/measure.test.exs @@ -30,7 +30,7 @@ alias Zenflows.VF.{Measure, Unit} embedded_schema do field :quantity, :map, virtual: true belongs_to :quantity_has_unit, Unit - field :quantity_has_numerical_value, :float + field :quantity_has_numerical_value, :decimal end def changeset(params) do @@ -56,11 +56,11 @@ setup do %{ params: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, inserted: %Dummy{ quantity_has_unit_id: Factory.insert!(:unit).id, - quantity_has_numerical_value: Factory.float(), + quantity_has_numerical_value: Factory.decimal(), }, } end @@ -77,7 +77,7 @@ test "insert", %{params: params} do # fields are properly set when `:quantity` is properly set assert %Changeset{valid?: true, changes: chgs} = Dummy.changeset(%{quantity: params}) assert chgs.quantity_has_unit_id == params.has_unit_id - assert chgs.quantity_has_numerical_value == params.has_numerical_value + assert Decimal.eq?(chgs.quantity_has_numerical_value, params.has_numerical_value) # `:has_numerical_value` must be positive assert %Changeset{valid?: false, errors: errs} @@ -130,7 +130,7 @@ test "update", %{params: params, inserted: schema} do assert %Changeset{valid?: true, changes: chgs} = Dummy.changeset(schema, %{quantity: params}) assert chgs.quantity_has_unit_id == params.has_unit_id - assert chgs.quantity_has_numerical_value == params.has_numerical_value + assert Decimal.eq?(chgs.quantity_has_numerical_value, params.has_numerical_value) # `:has_numerical_value` must be positive assert %Changeset{valid?: false, errors: errs} diff --git a/test/vf/process/track_and_trace.test.exs b/test/vf/process/track_and_trace.test.exs @@ -101,7 +101,7 @@ test "previous/2 works" do has_unit_id: unit.id, }, effort_quantity: %{ - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), has_unit_id: Factory.insert!(:unit).id, }, has_point_in_time: Factory.now(), diff --git a/test/vf/recipe_flow/domain.test.exs b/test/vf/recipe_flow/domain.test.exs @@ -38,11 +38,11 @@ setup do recipe_flow_resource_id: Factory.insert!(:recipe_resource).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, effort_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, recipe_clause_of_id: Factory.insert!(:recipe_exchange).id, note: Factory.str("some note"), @@ -72,7 +72,7 @@ describe "create/1" do assert new.recipe_flow_resource_id == params.recipe_flow_resource_id assert new.recipe_clause_of_id == params.recipe_clause_of_id assert new.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert new.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(new.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert new.effort_quantity_has_unit_id == nil assert new.effort_quantity_has_numerical_value == nil end @@ -89,7 +89,7 @@ describe "create/1" do assert new.resource_quantity_has_unit_id == nil assert new.resource_quantity_has_numerical_value == nil assert new.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert new.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(new.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) end test "with good params (with :resource_quantity and :effort_quantity): creates a RecipeFlow", %{params: params} do @@ -100,9 +100,9 @@ describe "create/1" do assert new.recipe_output_of_id == params.recipe_output_of_id assert new.recipe_flow_resource_id == params.recipe_flow_resource_id assert new.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert new.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(new.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert new.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert new.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(new.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) end test "with bad params (without :resource_qunatity and :effort_quantity): doesn't create a RecipeFlow", %{params: params} do @@ -134,9 +134,9 @@ describe "update/2" do assert new.recipe_flow_resource_id == params.recipe_flow_resource_id assert new.recipe_clause_of_id == params.recipe_clause_of_id assert new.resource_quantity_has_unit_id == params.resource_quantity.has_unit_id - assert new.resource_quantity_has_numerical_value == params.resource_quantity.has_numerical_value + assert Decimal.eq?(new.resource_quantity_has_numerical_value, params.resource_quantity.has_numerical_value) assert new.effort_quantity_has_unit_id == old.effort_quantity_has_unit_id - assert new.effort_quantity_has_numerical_value == old.effort_quantity_has_numerical_value + assert Decimal.eq?(new.effort_quantity_has_numerical_value, old.effort_quantity_has_numerical_value) end test "with good params (with :effort_quantity): updates the RecipeFlow", %{params: params, inserted: old} do @@ -149,9 +149,9 @@ describe "update/2" do assert new.recipe_flow_resource_id == params.recipe_flow_resource_id assert new.recipe_clause_of_id == params.recipe_clause_of_id assert new.resource_quantity_has_unit_id == old.resource_quantity_has_unit_id - assert new.resource_quantity_has_numerical_value == old.resource_quantity_has_numerical_value + assert Decimal.eq?(new.resource_quantity_has_numerical_value, old.resource_quantity_has_numerical_value) assert new.effort_quantity_has_unit_id == params.effort_quantity.has_unit_id - assert new.effort_quantity_has_numerical_value == params.effort_quantity.has_numerical_value + assert Decimal.eq?(new.effort_quantity_has_numerical_value, params.effort_quantity.has_numerical_value) end test "with good params (with :resource_quantity set to nil): updates the RecipeFlow", %{params: params, inserted: old} do @@ -170,7 +170,7 @@ describe "update/2" do assert new.resource_quantity_has_unit_id == nil assert new.resource_quantity_has_numerical_value == nil assert new.effort_quantity_has_unit_id == old.effort_quantity_has_unit_id - assert new.effort_quantity_has_numerical_value == old.effort_quantity_has_numerical_value + assert Decimal.eq?(new.effort_quantity_has_numerical_value, old.effort_quantity_has_numerical_value) end test "with good params (with :effort_quantity set to nil): updates the RecipeFlow", %{params: params, inserted: old} do @@ -187,7 +187,7 @@ describe "update/2" do assert new.recipe_flow_resource_id == params.recipe_flow_resource_id assert new.recipe_clause_of_id == params.recipe_clause_of_id assert new.resource_quantity_has_unit_id == old.resource_quantity_has_unit_id - assert new.resource_quantity_has_numerical_value == old.resource_quantity_has_numerical_value + assert Decimal.eq?(new.resource_quantity_has_numerical_value, old.resource_quantity_has_numerical_value) assert new.effort_quantity_has_unit_id == nil assert new.effort_quantity_has_numerical_value == nil end @@ -201,9 +201,9 @@ describe "update/2" do assert new.recipe_flow_resource_id == old.recipe_flow_resource_id assert new.recipe_clause_of_id == old.recipe_clause_of_id assert new.resource_quantity_has_unit_id == old.resource_quantity_has_unit_id - assert new.resource_quantity_has_numerical_value == old.resource_quantity_has_numerical_value + assert Decimal.eq?(new.resource_quantity_has_numerical_value, old.resource_quantity_has_numerical_value) assert new.effort_quantity_has_unit_id == old.effort_quantity_has_unit_id - assert new.effort_quantity_has_numerical_value == old.effort_quantity_has_numerical_value + assert Decimal.eq?(new.effort_quantity_has_numerical_value, old.effort_quantity_has_numerical_value) end test "with bad params (with :resource_quantity and :effort_quantity set to nil): doesn't update the RecipeFlow", %{params: params, inserted: old} do diff --git a/test/vf/recipe_flow/type.test.exs b/test/vf/recipe_flow/type.test.exs @@ -28,11 +28,11 @@ setup do "recipeFlowResource" => Factory.insert!(:recipe_resource).id, "resourceQuantity" => %{ "hasUnit" => Factory.insert!(:unit).id, - "hasNumericalValue" => Factory.float(), + "hasNumericalValue" => Factory.decimal(), }, "effortQuantity" => %{ "hasUnit" => Factory.insert!(:unit).id, - "hasNumericalValue" => Factory.float(), + "hasNumericalValue" => Factory.decimal(), }, "recipeClauseOf" => Factory.insert!(:recipe_exchange).id, }, @@ -74,9 +74,9 @@ describe "Query" do assert data["note"] == new.note assert data["action"]["id"] == new.action_id assert data["resourceQuantity"]["hasUnit"]["id"] == new.resource_quantity_has_unit_id - assert data["resourceQuantity"]["hasNumericalValue"] == new.resource_quantity_has_numerical_value + assert Decimal.eq?(data["resourceQuantity"]["hasNumericalValue"], new.resource_quantity_has_numerical_value) assert data["effortQuantity"]["hasUnit"]["id"] == new.effort_quantity_has_unit_id - assert data["effortQuantity"]["hasNumericalValue"] == new.effort_quantity_has_numerical_value + assert Decimal.eq?(data["effortQuantity"]["hasNumericalValue"], new.effort_quantity_has_numerical_value) assert data["recipeFlowResource"]["id"] == new.recipe_flow_resource_id assert data["recipeInputOf"]["id"] == new.recipe_input_of_id assert data["recipeOutputOf"]["id"] == new.recipe_output_of_id diff --git a/test/vf/recipe_process/domain.test.exs b/test/vf/recipe_process/domain.test.exs @@ -99,7 +99,7 @@ describe "create/1" do assert {:error, %Changeset{errors: errs}} = Domain.create(params) assert Keyword.has_key?(errs, :has_duration) - params = Map.put(params, :has_duration, %{numeric_duration: Factory.float()}) + params = Map.put(params, :has_duration, %{numeric_duration: Factory.decimal()}) assert {:error, %Changeset{errors: errs}} = Domain.create(params) assert Keyword.has_key?(errs, :has_duration) end diff --git a/test/vf/recipe_process/type.test.exs b/test/vf/recipe_process/type.test.exs @@ -24,7 +24,7 @@ setup do "name" => Factory.str("name"), "hasDuration" => %{ "unitType" => Factory.build(:time_unit) |> to_string(), - "numericDuration" => Factory.float(), + "numericDuration" => Factory.decimal(), }, "processClassifiedAs" => Factory.str_list("uri"), "processConformsTo" => Factory.insert!(:process_specification).id, @@ -64,8 +64,7 @@ describe "Query" do assert data["processClassifiedAs"] == new.process_classified_as assert data["processConformsTo"]["id"] == new.process_conforms_to_id assert data["hasDuration"]["unitType"] == to_string(new.has_duration_unit_type) - assert data["hasDuration"]["numericDuration"] == new.has_duration_numeric_duration - end + assert Decimal.eq?(data["hasDuration"]["numericDuration"], new.has_duration_numeric_duration) end end describe "Mutation" do diff --git a/test/vf/satisfaction.test.exs b/test/vf/satisfaction.test.exs @@ -27,11 +27,11 @@ setup do satisfies_id: Factory.insert!(:intent).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, effort_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, }} end diff --git a/test/vf/scenario_definition/type.test.exs b/test/vf/scenario_definition/type.test.exs @@ -25,7 +25,7 @@ setup do "note" => Factory.str("note"), "hasDuration" => %{ "unitType" => Factory.build(:time_unit) |> to_string(), - "numericDuration" => Factory.float(), + "numericDuration" => Factory.decimal(), }, }, inserted: Factory.insert!(:scenario_definition), @@ -58,7 +58,7 @@ describe "Query" do assert data["name"] == new.name assert data["note"] == new.note assert data["hasDuration"]["unitType"] == to_string(new.has_duration_unit_type) - assert data["hasDuration"]["numericDuration"] == new.has_duration_numeric_duration + assert Decimal.eq?(data["hasDuration"]["numericDuration"], new.has_duration_numeric_duration) end end diff --git a/test/vf/settlement.test.exs b/test/vf/settlement.test.exs @@ -27,11 +27,11 @@ setup do settles_id: Factory.insert!(:claim).id, resource_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, effort_quantity: %{ has_unit_id: Factory.insert!(:unit).id, - has_numerical_value: Factory.float(), + has_numerical_value: Factory.decimal(), }, }} end diff --git a/test/vf/spatial_thing/domain.test.exs b/test/vf/spatial_thing/domain.test.exs @@ -26,9 +26,9 @@ setup do params: %{ name: Factory.str("name"), mappable_address: Factory.str("address"), - lat: Factory.float(), - long: Factory.float(), - alt: Factory.float(), + lat: Factory.decimal(), + long: Factory.decimal(), + alt: Factory.decimal(), note: Factory.str("note"), }, inserted: Factory.insert!(:spatial_thing), @@ -50,9 +50,9 @@ describe "create/1" do assert {:ok, %SpatialThing{} = new} = Domain.create(params) assert new.name == params.name assert new.mappable_address == params.mappable_address - assert new.lat == params.lat - assert new.long == params.long - assert new.alt == params.alt + assert Decimal.eq?(new.lat, params.lat) + assert Decimal.eq?(new.long, params.long) + assert Decimal.eq?(new.alt, params.alt) assert new.note == params.note end @@ -66,9 +66,9 @@ describe "update/2" do assert {:ok, %SpatialThing{} = new} = Domain.update(old.id, params) assert new.name == params.name assert new.mappable_address == params.mappable_address - assert new.lat == params.lat - assert new.long == params.long - assert new.alt == params.alt + assert Decimal.eq?(new.lat, params.lat) + assert Decimal.eq?(new.long, params.long) + assert Decimal.eq?(new.alt, params.alt) assert new.note == params.note end @@ -76,9 +76,9 @@ describe "update/2" do assert {:ok, %SpatialThing{} = new} = Domain.update(old.id, %{}) assert new.name == old.name assert new.mappable_address == old.mappable_address - assert new.lat == old.lat - assert new.long == old.long - assert new.alt == old.alt + assert Decimal.eq?(new.lat, old.lat) + assert Decimal.eq?(new.long, old.long) + assert Decimal.eq?(new.alt, old.alt) assert new.note == old.note end end diff --git a/test/vf/spatial_thing/type.test.exs b/test/vf/spatial_thing/type.test.exs @@ -23,9 +23,9 @@ setup do params: %{ "name" => Factory.str("name"), "mappableAddress" => Factory.str("address"), - "lat" => Factory.float(), - "long" => Factory.float(), - "alt" => Factory.float(), + "lat" => Factory.decimal(), + "long" => Factory.decimal(), + "alt" => Factory.decimal(), "note" => Factory.str("note"), }, inserted: Factory.insert!(:spatial_thing), @@ -57,9 +57,9 @@ describe "Query" do assert data["id"] == new.id assert data["name"] == new.name assert data["mappableAddress"] == new.mappable_address - assert data["lat"] == new.lat - assert data["long"] == new.long - assert data["alt"] == new.alt + assert Decimal.eq?(data["lat"], new.lat) + assert Decimal.eq?(data["long"], new.long) + assert Decimal.eq?(data["alt"], new.alt) assert data["note"] == new.note end end