<commit_before>package tests.rescala.concurrency

import java.util.concurrent.{ConcurrentLinkedQueue, CountDownLatch}

import org.junit.Test
import org.scalatest.junit.AssertionsForJUnit
import rescala.turns.Engines
import rescala.{Signals, Var}

import scala.util.Random

class PaperGlitchTest extends AssertionsForJUnit {

  @Test def run(): Unit = {
    val lnOf2 = scala.math.log(2) // natural log of 2
    def log2(x: Double): Double = scala.math.log(x) / lnOf2
    def isPowerOf2(x: Int) = (x & (x - 1)) == 0

    // ============================================================================================================

    import Engines.unmanaged
    // <-- change here for FUN

    val price = Var(3)
    val tax = price.map { p => p / 3 }
    val quantity = Var(1)
    val total = Signals.mapping(quantity, price, tax) { implicit t =>
      quantity.now * (price.now + tax.now)
    }

    // ============================================================================================================

    val glitches = new ConcurrentLinkedQueue[Int]()

    total.changed += { v => if (!isPowerOf2(v)) glitches.add(v) }

    // ============================================================================================================

    @volatile var cancelled = false
<commit_msg>fix comment mutilated by autoformta<commit_after>package tests.rescala.concurrency

import java.util.concurrent.{ConcurrentLinkedQueue, CountDownLatch}

import org.junit.Test
import org.scalatest.junit.AssertionsForJUnit
import rescala.turns.Engines
import rescala.{Signals, Var}

import scala.util.Random

class PaperGlitchTest extends AssertionsForJUnit {

  @Test def run(): Unit = {
    val lnOf2 = scala.math.log(2) // natural log of 2
    def log2(x: Double): Double = scala.math.log(x) / lnOf2
    def isPowerOf2(x: Int) = (x & (x - 1)) == 0

    // ============================================================================================================

    // change here for FUN
    import Engines.unmanaged

    val price = Var(3)
    val tax = price.map { p => p / 3 }
    val quantity = Var(1)
    val total = Signals.mapping(quantity, price, tax) { implicit t =>
      quantity.now * (price.now + tax.now)
    }

    // ============================================================================================================

    val glitches = new ConcurrentLinkedQueue[Int]()

    total.changed += { v => if (!isPowerOf2(v)) glitches.add(v) }

    // ============================================================================================================

    @volatile var cancelled = false

{'fraction_non_alphanumeric': 0.34006092916984004, 'fraction_numerical': 0.00913937547600914, 'mean_word_length': 4.233067729083666, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '2367556', 'n_tokens_mistral': 759, 'n_tokens_neox': 683, 'n_words': 174}