<commit_before>Red/System [
	Title:   "Red/System integer! datatype tests"
	Author:  "<NAME>"
	File: 	 %float-test.reds
	Version: 0.1.0
	Rights:  "Copyright (C) 2012 <NAME>. All rights reserved."
	License: "BSD-3 - https://github.com/dockimbel/Red/blob/origin/BSD-3-License.txt"
]

#include %../../../../quick-test/quick-test.reds

~~~start-file~~~ "float"

===start-group=== "float assignment"
  --test-- "float-1"
    f: 100.0
  --assert f = 100.0
  --test-- "float-2"
    f: 1.222090944E+33
  --assert f = 1.222090944E+33
  --test-- "float-3"
    f: 9.99999E-45
  --assert f = 9.99999E-45
  --test-- "float-4"
    f: 1.0
    f1: f
  --assert f1 = 1.0
===end-group===

===start-group=== "float function arguments"
    ff: func [
      fff     [float!]
      ffg     [float!]
      return: [integer!]
      /local
      ffl [float!]
    ][
       ffl: fff
       if ffl <> fff [return 1]
       ffl: ffg
       if ffl <> ffg [return 2]
       1
    ]
    
  --test-- "float-func-args-1"
  --assert 1 = ff 1.0 2.0
  
  --test-- "float-func-args-2"
  --assert 1 = ff 1.222090944E+33 9.99999E-45
  
===end-group===

===start-group=== "float function return"

 
    ff1: func [
      ff1i      [integer!]
      return:   [float!]
    ][
      switch ff1i [
        1 [1.0]
        2 [1.222090944E+33]
        3 [9.99999E-45]
      ]
    ]
  --test-- "float return 1"
  --assert 1.0 = ff1 1
  --test-- "float return 2"
  --assert 1.222090944E+33 = ff1 2
  --test-- "float return 3"
  --assert 9.99999E-45 = ff1 3
  
===end-group===

===start-group=== "float struct!"

  --test-- "float-struct-1"
    sf1: declare struct! [
      a   [float!]
    ]
  --assert 0.0 = sf1/a
  
  --test-- "float-struct-2"
    sf2: declare struct! [
      a   [float!]
    ]
    sf1/a: 1.222090944E+33
  --assert 1.222090944E+33 = sf1/a

   
    sf3: declare struct! [
      a   [float!]
      b   [float!]
    ]
  
  --test-- "float-struct-3"
    sf3/a: 1.222090944E+33
    sf3/b: 9.99999E-45
    
  --assert 1.222090944E+33 = sf3/a
  --assert 9.99999E-45 = sf3/b
    
  --test-- "float-struct-4"
    sf4: declare struct! [
      c   [byte!]
      a   [float!]
      l   [logic!]
      b   [float!]
    ]
    sf4/a: 1.222090944E+33
    sf4/b: 9.99999E-45
  --assert 1.222090944E+33 = sf4/a
  --assert 9.99999E-45 = sf4/b

===end-group===

~~~end-file~~~<commit_msg>TESTS: added more float! datatype basic unit tests.<commit_after>Red/System [
	Title:   "Red/System integer! datatype tests"
	Author:  "<NAME>, <NAME>"
	File: 	 %float-test.reds
	Version: 0.1.0
	Rights:  "Copyright (C) 2012 <NAME>, <NAME>. All rights reserved."
	License: "BSD-3 - https://github.com/dockimbel/Red/blob/origin/BSD-3-License.txt"
]

#include %../../../../quick-test/quick-test.reds

~~~start-file~~~ "float"

===start-group=== "float assignment"
  --test-- "float-1"
    f: 100.0
  --assert f = 100.0
  --test-- "float-2"
    f: 1.222090944E+33
  --assert f = 1.222090944E+33
  --test-- "float-3"
    f: 9.99999E-45
  --assert f = 9.99999E-45
  --test-- "float-4"
    f: 1.0
    f1: f
  --assert f1 = 1.0
===end-group===

===start-group=== "float argument to external function"

	#import [
		LIBC-file cdecl [
			sin: "sin" [
				x 		[float!]
				return: [float!]
			]
			cos: "cos" [
				x 		[float!]
				return: [float!]
			]
		]
	]
	pi: 3.14159265358979
	
	--test-- "float-ext-1"
	--assert -1.0 = cos pi
	
	;--test-- "float-ext-2"
	;--assert  0.0 = sin pi		; not working, because of rounding error.
	
	--test-- "float-ext-3"
	--assert -1.0 = cos 3.14159265358979

===start-group=== "float function arguments"
    ff: func [
      fff     [float!]
      ffg     [float!]
      return: [integer!]
      /local
      ffl [float!]
    ][
       ffl: fff
       if ffl <> fff [return 1]
       ffl: ffg
       if ffl <> ffg [return 2]
       1
    ]
    
  --test-- "float-func-args-1"
  --assert 1 = ff 1.0 2.0
  
  --test-- "float-func-args-2"
  --assert 1 = ff 1.222090944E+33 9.99999E-45
  
===end-group===

===start-group=== "float locals"

	local-float: func [n [float!] return: [float!] /local p][p: n p]

	--test-- "float-loc-1"
	pi: local-float 3.14159265358979
	--assert pi = 3.14159265358979
	--assert -1.0 = cos pi
	--assert -1.0 = local-float cos pi
	
	--test-- "float-loc-2"
	f: local-float pi
	--assert pi = local-float f

	--test-- "float-loc-3"
	local-float2: func [n [float!] return: [float!] /local p][p: n local-float p]
	
	pi: local-float2 3.14159265358979
	--assert -1.0 = local-float2 cos pi
	f: local-float2 pi
	--assert pi = local-float2 f

	--test-- "float-loc-4"
	local-float3: func [n [float!] return: [float!] /local p [float!]][p: n local-float p]

	pi: local-float3 3.14159265358979
	--assert -1.0 = local-float3 cos pi
	f: local-float3 pi
	--assert pi = local-float3 f

	--test-- "float-loc-5"
	local-float4: func [n [float!] return: [float!] /local r p][p: n p]
	--assert -1.0 = local-float4 cos pi
	f: local-float4 pi
	--assert pi = local-float4 f
	
	--test-- "float-loc-6"
	local-float5: func [n [float!] return: [float!] /local r p][p: n local-float p]
	--assert -1.0 = local-float5 cos pi
	f: local-float5 pi
	--assert pi = local-float5 f

===end-group===

===start-group=== "float function return"

 
    ff1: func [
      ff1i      [integer!]
      return:   [float!]
    ][
      switch ff1i [
        1 [1.0]
        2 [1.222090944E+33]
        3 [9.99999E-45]
      ]
    ]
  --test-- "float return 1"
  --assert 1.0 = ff1 1
  --test-- "float return 2"
  --assert 1.222090944E+33 = ff1 2
  --test-- "float return 3"
  --assert 9.99999E-45 = ff1 3
  
===end-group===

===start-group=== "float members in struct"

  --test-- "float-struct-1"
    sf1: declare struct! [
      a   [float!]
    ]
  --assert 0.0 = sf1/a
  
  --test-- "float-struct-2"
    sf2: declare struct! [
      a   [float!]
    ]
    sf1/a: 1.222090944E+33
  --assert 1.222090944E+33 = sf1/a

   
    sf3: declare struct! [
      a   [float!]
      b   [float!]
    ]
  
  --test-- "float-struct-3"
    sf3/a: 1.222090944E+33
    sf3/b: 9.99999E-45
    
  --assert 1.222090944E+33 = sf3/a
  --assert 9.99999E-45 = sf3/b
    
  --test-- "float-struct-4"
    sf4: declare struct! [
      c   [byte!]
      a   [float!]
      l   [logic!]
      b   [float!]
    ]
    sf4/a: 1.222090944E+33
    sf4/b: 9.99999E-45
  --assert 1.222090944E+33 = sf4/a
  --assert 9.99999E-45 = sf4/b
  
  --test-- "float-struct-5"
  sf5: declare struct! [f [float!] i [integer!]]
  
  sf5/i: 1234567890
  sf5/f: 3.14159265358979
  --assert sf5/i = 1234567890
  --assert sf5/f = pi
  
  --test-- "float-struct-6"
  sf6: declare struct! [i [integer!] f [float!]]
  
  sf6/i: 1234567890
  sf6/f: 3.14159265358979
  --assert sf6/i = 1234567890
  --assert sf6/f = pi

===end-group===

===start-group=== "float pointers"

  --test-- "float-point-1"
  pi: 3.14159265358979
  p: declare pointer! [float!]
  p/value: 3.14159265358979
  --assert pi = p/value
 
 ;TBD: add more float pointer tests in %pointer-test.reds.

===end-group===

~~~end-file~~~
{'fraction_non_alphanumeric': 0.18874409279679222, 'fraction_numerical': 0.11628240011456394, 'mean_word_length': 1.9744463373083476, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4220561', 'n_tokens_mistral': 3481, 'n_tokens_neox': 2970, 'n_words': 704}