Inheritance: MonoBehaviour
Exemplo n.º 1
0
        public void SpinEquality()
        {
            Spin s0  = Spin.SpinZero;
            Spin s1a = Spin.SpinOne;
            Spin s1b = new Spin(1.0);

            Assert.IsTrue(s1a == s1b);
            Assert.IsTrue(s0 != s1a);

            SpinState[] ss = s1a.States();
            Assert.IsTrue(ss.Length == s1a.Dimension);
            for (int i = 0; i < ss.Length; i++)
            {
                for (int j = 0; j < ss.Length; j++)
                {
                    if (i == j)
                    {
                        Assert.IsTrue(ss[i] == ss[j]);
                    }
                    else
                    {
                        Assert.IsTrue(ss[i] != ss[j]);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public virtual void testSerializationAsXml()
        {
            ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");

            XmlSerializable bean = new XmlSerializable("a String", 42, true);

            // request object to be serialized as XML
            runtimeService.setVariable(instance.Id, "simpleBean", objectValue(bean).serializationDataFormat(XML_FORMAT_NAME).create());

            // validate untyped value
            object value = runtimeService.getVariable(instance.Id, "simpleBean");

            assertEquals(bean, value);

            // validate typed value
            ObjectValue typedValue = runtimeService.getVariableTyped(instance.Id, "simpleBean");

            assertEquals(ValueType.OBJECT, typedValue.Type);

            assertTrue(typedValue.Deserialized);

            assertEquals(bean, typedValue.Value);
            assertEquals(bean, typedValue.getValue(typeof(XmlSerializable)));
            assertEquals(typeof(XmlSerializable), typedValue.ObjectType);

            assertEquals(XML_FORMAT_NAME, typedValue.SerializationDataFormat);
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            assertEquals(typeof(XmlSerializable).FullName, typedValue.ObjectTypeName);
            SpinXmlElement serializedValue = Spin.XML(typedValue.ValueSerialized);

            assertEquals(bean.StringProperty, serializedValue.childElement("stringProperty").textContent());
            assertEquals(bean.BooleanProperty, bool.Parse(serializedValue.childElement("booleanProperty").textContent()));
            assertEquals(bean.IntProperty, int.Parse(serializedValue.childElement("intProperty").textContent()));
        }
Exemplo n.º 3
0
        public void SixJReggeSymmetry()
        {
            SixJSymbol[] symbols = GenerateRandomSixJSymbols(15.0, 15);
            foreach (SixJSymbol symbol in symbols)
            {
                Spin sa1 = symbol.J1;
                Spin sa2 = symbol.J2;
                Spin sa3 = symbol.J3;
                Spin sa4 = symbol.J4;
                Spin sa5 = symbol.J5;
                Spin sa6 = symbol.J6;

                Console.WriteLine("{0} {1} {2}", sa1.J, sa2.J, sa3.J);
                Console.WriteLine("{0} {1} {2}", sa4.J, sa5.J, sa6.J);

                double sa = SpinMath.SixJ(sa1, sa2, sa3, sa4, sa5, sa6);

                Spin sb1 = new Spin(sa1.J);
                Spin sb2 = new Spin((sa3.J + sa5.J + sa6.J - sa2.J) / 2.0);
                Spin sb3 = new Spin((sa2.J + sa5.J + sa6.J - sa3.J) / 2.0);
                Spin sb4 = new Spin(sa4.J);
                Spin sb5 = new Spin((sa2.J + sa3.J + sa6.J - sa5.J) / 2.0);
                Spin sb6 = new Spin((sa2.J + sa3.J + sa5.J - sa6.J) / 2.0);

                Console.WriteLine("{0} {1} {2}", sb1.J, sb2.J, sb3.J);
                Console.WriteLine("{0} {1} {2}", sb4.J, sb5.J, sb6.J);

                double sb = SpinMath.SixJ(sb1, sb2, sb3, sb4, sb5, sb6);

                Console.WriteLine("{0} vs. {1}", sa, sb);
                Console.WriteLine("---");

                Assert.IsTrue(TestUtilities.IsNearlyEqual(sa, sb));
            }
        }
Exemplo n.º 4
0
        public IHttpActionResult PutSpin(int id, Spin spin)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != spin.Id)
            {
                return(BadRequest());
            }

            db.Entry(spin).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SpinExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IActionResult Index(Player player)
        {
            Spin spin = new Spin();

            spin.Luck = player.Lucky;
            return(RedirectToAction("SpinIt", spin));
        }
Exemplo n.º 6
0
 protected virtual void OnSpin(DreidelEventArgs e)
 {
     if (Spin != null)
     {
         Spin.Invoke(this, e);
     }
 }
 public SpinDTO(Spin spin)
 {
     PlayedAmount = spin.PlayedAmount;
     Win          = spin.Win;
     TotalAmount  = spin.TotalAmount;
     TimeStamp    = spin.TimeStamp;
 }
Exemplo n.º 8
0
    //Handles stopping the Reels in the correct order and evaulating the win
    IEnumerator beginStopSpin()
    {
        isSpinning = true;
        result     = getRandomSpin();
        yield return(new WaitForSeconds(1));

        reelSpinnerManager.stopReel(0, result.ReelIndex[0], result.ActiveReelCount > 0);
        yield return(reelSpinnerManager.waitForReelToStop(0));

        yield return(new WaitForSeconds(.3f));

        reelSpinnerManager.stopReel(1, result.ReelIndex[1], result.ActiveReelCount > 1);
        yield return(reelSpinnerManager.waitForReelToStop(1));

        yield return(new WaitForSeconds(.3f));

        reelSpinnerManager.stopReel(2, result.ReelIndex[2], result.ActiveReelCount > 2);
        yield return(reelSpinnerManager.waitForReelToStop(2));

        if (result.WinAmount > 0)
        {
            onWin?.Invoke(result.WinAmount);
            reelSpinnerManager.animateReels(result.ActiveReelCount);
        }

        isSpinning = false;
    }
Exemplo n.º 9
0
    void Awake()
    {
        image   = GetComponent <Image>();
        isBlack = true;

        spinAnimation = GetComponent <Spin>();
    }
Exemplo n.º 10
0
        public void Hash()
        {
            var spin1 = new Spin(10);
            var spin2 = new Spin(40);

            var dictionary = new Dictionary <Spin, int>();

            dictionary.Add(spin1, dictionary.Count);

            try
            {
                dictionary.Add(spin2, dictionary.Count);
            }
            catch
            {
                Assert.True(false, $"{typeof(Spin)} must not throw exception.");
            }

            try
            {
                dictionary.Add(spin2, dictionary.Count);
                Assert.True(false, $"{typeof(Spin)} must throw exception because key is duplicate.");
            }
            catch (ArgumentException)
            {
            }
        }
        public async Task <Result <bool> > InsertSpin(string userId, double playedAmount, WheelSegment segment)
        {
            var user = await context.Users.FindAsync(Guid.Parse(userId));

            if (user == null)
            {
                return(Result <bool> .CreateFailed(
                           HttpStatusCode.NotFound, "Αδυναμία ανάκτησης υπολοιίου"));
            }
            var spin = new Spin();

            spin.PlayedAmount = playedAmount;
            spin.TimeStamp    = DateTime.Now;
            spin.Win          = segment.Win;
            spin.TotalAmount  = playedAmount * segment.Multiplier;
            spin.User         = user;
            try
            {
                await context.Spins.AddAsync(spin);

                await context.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(Result <bool> .CreateFailed(
                           HttpStatusCode.NotFound, "Αδυναμία ανάκτησης υπολοιίου"));
            }
            return(Result <bool> .CreateSuccessful(true));
        }
Exemplo n.º 12
0
        public IEnumerable <IDanceStep> ParseSteps(string input)
        {
            var rawSteps            = input.Split(",", StringSplitOptions.RemoveEmptyEntries);
            List <IDanceStep> steps = new List <IDanceStep>();

            foreach (var rawStep in rawSteps)
            {
                switch (rawStep.First())
                {
                case 's':
                    steps.Add(Spin.CreateFromString(rawStep));
                    break;

                case 'x':
                    steps.Add(Exchange.CreateFromString(rawStep));
                    break;

                case 'p':
                    steps.Add(Partner.CreateFromString(rawStep));
                    break;

                default:
                    throw new Exception("Unrecognized dance format: " + rawStep);
                }
            }
            return(steps);
        }
Exemplo n.º 13
0
 private void brush_PointerPressed(object sender, PointerRoutedEventArgs e)
 {
     Spin.Stop();
     WB1.Visibility   = Visibility.Visible;
     brush.Visibility = Visibility.Collapsed;
     animating        = false;
 }
Exemplo n.º 14
0
 public void SetRotation(Vector3 axis, float speed)
 {
     CurrentSpin = new Spin()
     {
         Axis = axis, Speed = speed
     };
 }
Exemplo n.º 15
0
        public void SixJExchangeSymmetry()
        {
            SixJSymbol[] symbols = GenerateRandomSixJSymbols(50.0, 5);
            foreach (SixJSymbol symbol in symbols)
            {
                Spin j1 = symbol.J1;
                Spin j2 = symbol.J2;
                Spin j3 = symbol.J3;
                Spin j4 = symbol.J4;
                Spin j5 = symbol.J5;
                Spin j6 = symbol.J6;

                double s1 = SpinMath.SixJ(j1, j2, j3, j4, j5, j6);

                // odd column permutation
                double s2 = SpinMath.SixJ(j2, j1, j3, j5, j4, j6);
                Assert.IsTrue(TestUtilities.IsNearlyEqual(s1, s2));

                // even column permutation
                double s3 = SpinMath.SixJ(j2, j3, j1, j5, j6, j4);
                Assert.IsTrue(TestUtilities.IsNearlyEqual(s1, s3));

                // flip
                double s4 = SpinMath.SixJ(j1, j5, j6, j4, j2, j3);
                Assert.IsTrue(TestUtilities.IsNearlyEqual(s1, s4));
            }
        }
    public void StartSpin()
    {
        Spin spin = GetComponent <Spin>();

        spin.enabled = true;
        ritualDisplay.SetActive(true);
    }
Exemplo n.º 17
0
        public void TestSpin(int steps, string expected)
        {
            var sut     = new Spin($"s{steps}");
            var dancers = "abcde";
            var result  = sut.Execute(dancers);

            Assert.Equal(expected, result);
        }
Exemplo n.º 18
0
    public void DisableSpinX()
    {
        Spin spin = controllingObject.GetComponent <Spin>();

        spin.spinX = false;
        controllingObject2.GetComponent <MovingPlatform>().enabled = true;
        GetComponent <AudioSource>().enabled = true;
    }
Exemplo n.º 19
0
 public Rover move_using(string instructions)
 {
     foreach (var instruction in instructions)
     {
         Spin.Get(instruction).apply(rover_tasks, rover);
     }
     return(rover);
 }
Exemplo n.º 20
0
        public void CustomViewPropertyTest()
        {
            // Create a Spin control
            Spin spin = new Spin();

            // Background property
            PropertyMap background = new PropertyMap();

            background.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Color))
            .Add(ColorVisualProperty.MixColor, new PropertyValue(Color.Red));
            spin.Background = background;

            background = spin.Background;
            Color backgroundColor = new Color();

            background.Find(ColorVisualProperty.MixColor, "mixColor")?.Get(backgroundColor);
            if (backgroundColor == Color.Red)
            {
                Tizen.Log.Debug("NUI", "Custom View Background property : test passed");
            }
            else
            {
                Tizen.Log.Debug("NUI", "Custom View Background property : test failed");
            }

            // BackgroundColor property
            spin.BackgroundColor = Color.Yellow;
            if (spin.BackgroundColor == Color.Yellow)
            {
                Tizen.Log.Debug("NUI", "Custom View BackgroundColor property : test passed");
            }
            else
            {
                Tizen.Log.Debug("NUI", "Custom View BackgroundColor property : test failed");
            }

            // BackgroundImage property
            spin.BackgroundImage = "background-image.jpg";
            if (spin.BackgroundImage == "background-image.jpg")
            {
                Tizen.Log.Debug("NUI", "Custom View BackgroundImage property : test passed");
            }
            else
            {
                Tizen.Log.Debug("NUI", "Custom View BackgroundImage property : test failed");
            }

            // StyleName property
            spin.StyleName = "MyCustomStyle";
            if (spin.StyleName == "MyCustomStyle")
            {
                Tizen.Log.Debug("NUI", "Custom View StyleName property : test passed");
            }
            else
            {
                Tizen.Log.Debug("NUI", "Custom View StyleName property : test failed");
            }
        }
Exemplo n.º 21
0
 public static void Spin(Spin spin, Action<string> callback)
 {
     var response = new Dictionary<string, object>();
     response["status"] = "OK";
     response["results"] = GetSpinResults(spin);
     var text = JsonMapper.ToJson(response);
     Debug.Log (text);
     callback(text);
 }
Exemplo n.º 22
0
        public void CreateFromStrings()
        {
            var spin = Spin.CreateFromString("s1");

            Assert.Equal(1, spin.Amount);

            spin = Spin.CreateFromString("s34233");
            Assert.Equal(34233, spin.Amount);
        }
Exemplo n.º 23
0
        private void DrawSpin(Spin p)
        {
            int left = p.Index % N;
            int top  = p.Index / N;

            _wbmap.Lock();
            DrawSpin(left, top, p.Color);
            _wbmap.Unlock();
        }
Exemplo n.º 24
0
    public void DisableSpinY()
    {
        Spin spin = controllingObject.GetComponent <Spin>();

        spin.spinY = false;
        controllingObject2.transform.localScale = Vector3.Lerp(controllingObject2.transform.localScale, new Vector3(10, 10, 10), 0.01f);
        controllingObject2.GetComponent <Teleport>().enabled = true;
        GetComponent <AudioSource>().enabled = true;
    }
Exemplo n.º 25
0
    // Use this for initialization
    void Start()
    {
        if (waypoint != null)
        {
            Destroy(gameObject);
        }
        else waypoint = this;

        timerInit = timeToDestroy;
    }
Exemplo n.º 26
0
        public void Equal()
        {
            var spin1 = new Spin(10);
            var spin2 = new Spin(10);

            Assert.Equal(spin1, spin2);
            Assert.True(spin1 == spin2);
            Assert.True(spin1.Equals(spin2));
            Assert.False(spin1 != spin2);
        }
Exemplo n.º 27
0
 public void PresentSpin(Spin _Spin)
 {
     if (m_PresentSpin != null)
     {
         StopCoroutine(m_PresentSpin);
         m_PresentSpin = null;
     }
     m_PresentSpin = PresentSpinCoroutine(_Spin);
     StartCoroutine(m_PresentSpin);
 }
Exemplo n.º 28
0
 /// <summary>
 /// returns the DoubleMatrix for the given spin
 /// </summary>
 public Band_Data Spin_Data(Spin spin)
 {
     if (spin == Spin.Up)
     {
         return(spin_data[0]);
     }
     else
     {
         return(spin_data[1]);
     }
 }
Exemplo n.º 29
0
        /// <summary>
        /// Informs the control that a thread is entering a block of code or that it is beginning to consuming a resource and
        /// specifies a timeout threshold.
        /// </summary>
        /// <param name="blockTimeoutThreshold">
        /// The maximum length of time to block a thread before raising an exception.
        /// </param>
        /// <exception cref="LockRecursionException">
        /// The current thread already owns the lock.
        /// </exception>
        /// <exception cref="TimeoutException">
        /// The operation timed out.
        /// </exception>
        protected sealed override void EnterWithTimeout(TimeSpan blockTimeoutThreshold)
        {
            var lockTaken = false;

            Spin.TryEnter(blockTimeoutThreshold, ref lockTaken);

            if (lockTaken == false)
            {
                throw new TimeoutException($"The operation failed to acquire a spin lock after {blockTimeoutThreshold.ToSerializedString()}.");
            }
        }
Exemplo n.º 30
0
 private void LayoutRoot_PointerMoved(object sender, PointerRoutedEventArgs e)
 {
     dt.Start();
     if (!animating)
     {
         WB1.Visibility   = Visibility.Collapsed;
         brush.Visibility = Visibility.Visible;
         Spin.Begin();
         animating = true;
     }
 }
Exemplo n.º 31
0
        /// <summary>
        /// Informs the control that a thread is entering a block of code or that it is beginning to consuming a resource.
        /// </summary>
        /// <exception cref="ConcurrencyControlOperationException">
        /// The lock was not acquired.
        /// </exception>
        /// <exception cref="LockRecursionException">
        /// The current thread already owns the lock.
        /// </exception>
        protected sealed override void EnterWithoutTimeout()
        {
            var lockTaken = false;

            Spin.TryEnter(ref lockTaken);

            if (lockTaken == false)
            {
                throw new ConcurrencyControlOperationException("The operation failed to acquire a spin lock.");
            }
        }
Exemplo n.º 32
0
        public void RearrangePrograms()
        {
            var spin  = new Spin(3);
            var input = new char[] { 'a', 'b', 'c', 'd', 'e' };

            Assert.Equal(new char[] { 'c', 'd', 'e', 'a', 'b' }, spin.ApplyStep(input));

            spin  = new Spin(1);
            input = new char[] { 'a', 'b', 'c', 'd', 'e' };
            Assert.Equal(new char[] { 'e', 'a', 'b', 'c', 'd' }, spin.ApplyStep(input));
        }
Exemplo n.º 33
0
        /// <summary>
        /// Instantiates a new SpinState with the given spin and magnetic quantum number.
        /// </summary>
        /// <param name="s">The spin.</param>
        /// <param name="m">The magnetic quantum number.</param>
        public SpinState(Spin s, double m)
        {
            spin = s;

            // 2M must be an integer
            double tm = 2.0 * m;
            double tmt = Math.Floor(tm);
            if (tmt != tm) throw new ArgumentOutOfRangeException("m");

            int tmti = (int)tmt;

            twoM = (int)tmt;
            // -J <= M <= J
            if (Math.Abs(tmti) > s.TwoJ) throw new ArgumentOutOfRangeException("m");

            // half-integer J requires half-integer M; integer J requires integer M
            if ((s.TwoJ % 2) != Math.Abs(twoM % 2)) throw new ArgumentOutOfRangeException("m");
        }
Exemplo n.º 34
0
        public void SpinEquality()
        {
            Spin s0 = Spin.SpinZero;
            Spin s1a = Spin.SpinOne;
            Spin s1b = new Spin(1.0);

            Assert.IsTrue(s1a == s1b);
            Assert.IsTrue(s0 != s1a);

            SpinState[] ss = s1a.States();
            Assert.IsTrue(ss.Length == s1a.Dimension);
            for (int i = 0; i < ss.Length; i++) {
                for (int j = 0; j < ss.Length; j++) {
                    if (i == j) {
                        Assert.IsTrue(ss[i] == ss[j]);
                    } else {
                        Assert.IsTrue(ss[i] != ss[j]);
                    }
                }
            }
        }
Exemplo n.º 35
0
 void Spin()
 {
     spinButton.enabled = false;
     spinData = null;
     spinning = true;
     var bet = m_betAmounts[m_betIdx];
     var spin = new Spin(m_lines[m_lineIdx], bet);
     ContentManager.Instance.Player.IncrementCredits(-bet * m_lineCounts[m_lineIdx]);
     UpdateLabels();
     ResetReelChecks ();
     if(this.USE_BAKED_LOGIC) {
         DemoSpinner.Spin(spin, (text) => {
             Debug.Log ("Spin done!");
             Debug.Log ("Got spin: " + text);
             LitJson.JsonData jdata = LitJson.JsonMapper.ToObject<LitJson.JsonData>(text);
             spinData = new SpinResponse(jdata);
         });
     }
     else {
         ConnectionProxy.Connection.SendMessage(spin, (jdata) => {
             Debug.Log ("Spin done!");
             Debug.Log (jdata["results"]);
             spinData = new SpinResponse(jdata);
         });
     }
 }
Exemplo n.º 36
0
 /// <summary>
 /// returns the DoubleMatrix for the given spin
 /// </summary>
 public DoubleMatrix Spin_Matrix(Spin spin)
 {
     if (spin == Spin.Up)
         return spin_matrix[0];
     else
         return spin_matrix[1];
 }
Exemplo n.º 37
0
 public double this[int i, int j, Spin spin]
 {
     get { return this.Spin_Matrix(spin)[i, j]; }
     set { this.Spin_Matrix(spin)[i, j] = value; }
 }
Exemplo n.º 38
0
 public void SpinInvalid1()
 {
     // spin indices are non-negative
     Spin s = new Spin(-1.0);
 }
Exemplo n.º 39
0
        public void SixJZeroMinimum()
        {
            // we include these special cases in order to exercise code in the recursion routine that is active
            // only when the minimum spin of the recursion is zero

            Spin s1 = Spin.SpinOne;
            Spin s2 = new Spin(2.0);
            Spin s3 = new Spin(3.0);

            Assert.IsTrue(TestUtilities.IsNearlyEqual(SpinMath.SixJ(s2, s2, s2, s1, s2, s2), -1.0 / 10.0));

            Assert.IsTrue(TestUtilities.IsNearlyEqual(SpinMath.SixJ(s2, s2, s2, s2, s2, s2), -3.0 / 70.0));

            Assert.IsTrue(TestUtilities.IsNearlyEqual(SpinMath.SixJ(s2, s2, s2, s3, s2, s2), 4.0 / 35.0));
        }
Exemplo n.º 40
0
        private static SpinRange CombinedSpinRange(Spin j1, Spin j2)
        {
            int tj1 = (int) Math.Round(2 * j1.J);
            int tj2 = (int) Math.Round(2 * j2.J);

            int tj_min = Math.Abs(tj1 - tj2);
            int tj_max = tj1 + tj2;

            SpinRange range = new SpinRange();
            range.Minimum = new Spin(tj_min / 2.0);
            range.Maximum = new Spin(tj_max / 2.0);

            return (range);
        }
Exemplo n.º 41
0
 public void SpinInvalid2()
 {
     // spin indices are integer or half-integer
     Spin s = new Spin(1.25);
 }
Exemplo n.º 42
0
    static Dictionary<string, object> GetSpinResults(Spin spin)
    {
        var response = new Dictionary<string, object>();
        var reels = SpinReels();
        var gems = GetGemLocations();
        response["reels"] = reels;
        response["gems"] = gems;

        var results = new Dictionary<string, object>();
        var totalCredits = 0;
        var totalRed = 0;
        var totalGreen = 0;
        var totalBlue = 0;
        var lines = new List<object>();
        Debug.Log ("Bet is: " + spin.bet);
        for(var i = 0; i < spin.lines.Length; i++) {
            var line = CheckLine(reels, gems, i, spin.lines[i]);
            line["credits"] = (int)line["credits"] * spin.bet;
            var credits = (int)line["credits"];
            totalCredits += credits;
            if(credits > 0) {
                totalRed += (int)line["red_gems"];
                totalGreen += (int)line["green_gems"];
                totalBlue += (int)line["blue_gems"];
            }
            lines.Add (line);
        }
        results["total_credits"] = totalCredits;
        if(totalCredits > 0) {
            var wheel = GenerateWheelSpin();
            results["wheel"] = (int)wheel;
            if(wheelHits.SetMark(wheel)) {
                results["wheel_reward"] = 10000;
                wheelHits.ClearForMark(wheel);
            }
            // FIXME: Server side should be passing rewards when player has unlocked a set
        }
        results["total_red_gems"] = totalRed;
        results["total_green_gems"] = totalGreen;
        results["total_blue_gems"] = totalBlue;
        results["xp"] = 0;
        results["paylines"] = lines;
        response["results"] = results;
        return response;
    }
Exemplo n.º 43
0
        public void SixJReggeSymmetry()
        {
            SixJSymbol[] symbols = GenerateRandomSixJSymbols(15.0, 15);
            foreach (SixJSymbol symbol in symbols) {

                Spin sa1 = symbol.J1;
                Spin sa2 = symbol.J2;
                Spin sa3 = symbol.J3;
                Spin sa4 = symbol.J4;
                Spin sa5 = symbol.J5;
                Spin sa6 = symbol.J6;

                Console.WriteLine("{0} {1} {2}", sa1.J, sa2.J, sa3.J);
                Console.WriteLine("{0} {1} {2}", sa4.J, sa5.J, sa6.J);

                double sa = SpinMath.SixJ(sa1, sa2, sa3, sa4, sa5, sa6);

                Spin sb1 = new Spin(sa1.J);
                Spin sb2 = new Spin((sa3.J + sa5.J + sa6.J - sa2.J) / 2.0);
                Spin sb3 = new Spin((sa2.J + sa5.J + sa6.J - sa3.J) / 2.0);
                Spin sb4 = new Spin(sa4.J);
                Spin sb5 = new Spin((sa2.J + sa3.J + sa6.J - sa5.J) / 2.0);
                Spin sb6 = new Spin((sa2.J + sa3.J + sa5.J - sa6.J) / 2.0);

                Console.WriteLine("{0} {1} {2}", sb1.J, sb2.J, sb3.J);
                Console.WriteLine("{0} {1} {2}", sb4.J, sb5.J, sb6.J);

                double sb = SpinMath.SixJ(sb1, sb2, sb3, sb4, sb5, sb6);

                Console.WriteLine("{0} vs. {1}", sa, sb);
                Console.WriteLine("---");

                Assert.IsTrue(TestUtilities.IsNearlyEqual(sa, sb));

            }
        }
Exemplo n.º 44
0
        public void ClebschGordonOrthonormalityMM()
        {
            int t00 = 0;
            int t01 = 0;
            int t1 = 1;

            foreach (Spin j1 in GenerateRandomSpins(0.0, 50.0, 4)) {
                foreach (Spin j2 in GenerateRandomSpins(0.0, 50.0, 4)) {
                    foreach (SpinState s1a in GenerateRandomSpinStates(j1, 4)) {
                        foreach (SpinState s1b in GenerateRandomSpinStates(j1, 4)) {
                            foreach (SpinState s2a in GenerateRandomSpinStates(j2, 4)) {
                                foreach (SpinState s2b in GenerateRandomSpinStates(j2, 4)) {

                                    // if the sum of M's are equal, all terms will be trivially zero
                                    if ((s1a.M + s2a.M) != (s1b.M + s2b.M)) continue;

                                    // sum over j and m
                                    double s = 0.0;
                                    bool nonZero = false;

                                    double j_min = Math.Abs(j1.J - j2.J);
                                    double j_max = j1.J + j2.J;
                                    for (double j = j_min; j <= j_max; j = j + 1.0) {
                                        Spin j3 = new Spin(j);
                                        foreach (SpinState s3 in j3.States()) {
                                            double ds = SpinMath.ClebschGodron(s1a, s2a, s3) * SpinMath.ClebschGodron(s1b, s2b, s3);
                                            if (ds != 0.0) nonZero = true;
                                            s += ds;
                                        }
                                    }

                                    if ((s1a.M == s1b.M) && (s2a.M == s2b.M)) {
                                        Assert.IsTrue(TestUtilities.IsNearlyEqual(s, 1.0));
                                        t1++;
                                    } else {
                                        Assert.IsTrue(Math.Abs(s) < TestUtilities.TargetPrecision);
                                        if (nonZero) {
                                            t01++;
                                        } else {
                                            t00++;
                                        }
                                    }

                                }
                            }
                        }
                    }
                }
            }

            Console.WriteLine("Trivial zeros: {0}", t00);
            Console.WriteLine("Non-trivial zerios: {0}", t01);
            Console.WriteLine("Ones: {0}", t1);
        }
Exemplo n.º 45
0
 public double this[int i, Spin spin]
 {
     get { return this.Spin_Vector(spin)[i]; }
     set { this.Spin_Vector(spin)[i] = value; }
 }
Exemplo n.º 46
0
        private static Spin[] GenerateRandomCombinedSpins(Spin j1, Spin j2, int n)
        {
            int tj_min = (int) (2.0 * Math.Abs(j1.J - j2.J));
            int tj_max = (int) (2.0 * (j1.J + j2.J));

            Spin[] spins = new Spin[n];
            Random rng = new Random(1);
            for (int i = 0; i < n; i++) {
                int tj = tj_min + 2 * rng.Next((tj_max - tj_min) / 2);
                spins[i] = new Spin(tj / 2.0);
            }

            return (spins);
        }
Exemplo n.º 47
0
 /// <summary>
 /// returns the DoubleMatrix for the given spin
 /// </summary>
 public Band_Data Spin_Data(Spin spin)
 {
     if (spin == Spin.Up)
         return spin_data[0];
     else
         return spin_data[1];
 }
Exemplo n.º 48
0
        private static SpinState[] GenerateRandomSpinStates(Spin j, int n)
        {
            int tj = (int) (2.0 * j.J);

            SpinState[] result = new SpinState[n];
            Random rng = new Random(1);
            for (int i = 0; i < n; i++) {

                int tm = -tj + 2 * rng.Next(tj + 1);
                result[i] = new SpinState(j, tm / 2.0);

            }

            return (result);
        }
Exemplo n.º 49
0
        private static Spin[] GenerateCombinedSpins(Spin j1, Spin j2)
        {
            int tj_min = (int) (2.0 * Math.Abs(j1.J - j2.J));
            int tj_max = (int) (2.0 * (j1.J + j2.J));

            List<Spin> spins = new List<Spin>();
            for (int tj = tj_min; tj <= tj_max; tj += 2) {
                spins.Add(new Spin(tj / 2.0));
            }

            return (spins.ToArray());
        }
Exemplo n.º 50
0
        private static Spin[] GenerateRandomSpins(double j_min, double j_max, int n)
        {
            int tj_min = (int) Math.Truncate(2.0 * j_min);
            int tj_max = (int) Math.Truncate(2.0 * j_max);

            Spin[] spins = new Spin[n];
            Random rng = new Random(1);
            for (int i = 0; i < n; i++) {
                spins[i] = new Spin(rng.Next(tj_min, tj_max) / 2.0);
            }

            return (spins);
        }
Exemplo n.º 51
0
        private static Spin[] RandomSpinsInRange(SpinRange range, int n)
        {
            int tj_min = (int) Math.Truncate(2.0 * range.Minimum.J);
            int tj_max = (int) Math.Truncate(2.0 * range.Maximum.J);

            Spin[] spins = new Spin[n];
            Random rng = new Random(1);
            for (int i = 0; i < n; i++) {
                spins[i] = new Spin((tj_min + 2 * rng.Next((tj_max - tj_min) / 2 + 1))/2.0);
            }

            return (spins);
        }
Exemplo n.º 52
0
 /// <summary>
 /// returns the DoubleMatrix for the given spin
 /// </summary>
 public DoubleVector Spin_Vector(Spin spin)
 {
     if (spin == Spin.Up)
         return spin_vector[0];
     else
         return spin_vector[1];
 }